vcl: cleanup and fixes for vcl test code
- better approximate time when test finishes
- move common vcl and sock test code to vcl_test.h
- overall refactor of variable names
Change-Id: I8e6b43fc017cd05a0ddaa3891767a44fb300c09e
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vcl/CMakeLists.txt b/src/vcl/CMakeLists.txt
index 9fead60..abe1bf0 100644
--- a/src/vcl/CMakeLists.txt
+++ b/src/vcl/CMakeLists.txt
@@ -44,7 +44,6 @@
vcl_test.h
vppcom.h
ldp_socket_wrapper.h
- sock_test_common.h
)
##############################################################################
diff --git a/src/vcl/sock_test.h b/src/vcl/sock_test.h
index 6e0b22a..83f17fa 100644
--- a/src/vcl/sock_test.h
+++ b/src/vcl/sock_test.h
@@ -20,16 +20,18 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <vcl/sock_test_common.h>
+#include <vcl/vcl_test.h>
#define SOCK_TEST_AF_UNIX_FILENAME "/tmp/ldp_server_af_unix_socket"
#define SOCK_TEST_MIXED_EPOLL_DATA "Hello, world! (over an AF_UNIX socket)"
#define SOCK_TEST_AF_UNIX_ACCEPT_DATA 0xaf0000af
#define SOCK_TEST_AF_UNIX_FD_MASK 0x00af0000
+#define SOCK_TEST_BANNER_STRING \
+ "============================================\n"
static inline int
sock_test_read (int fd, uint8_t *buf, uint32_t nbytes,
- sock_test_stats_t *stats)
+ vcl_test_stats_t *stats)
{
int rx_bytes, errno_val;
@@ -66,7 +68,7 @@
static inline int
sock_test_write (int fd, uint8_t *buf, uint32_t nbytes,
- sock_test_stats_t *stats, uint32_t verbose)
+ vcl_test_stats_t *stats, uint32_t verbose)
{
int tx_bytes = 0;
int nbytes_left = nbytes;
diff --git a/src/vcl/sock_test_client.c b/src/vcl/sock_test_client.c
index de77fc9..75913d9 100644
--- a/src/vcl/sock_test_client.c
+++ b/src/vcl/sock_test_client.c
@@ -38,8 +38,8 @@
struct sockaddr_storage server_addr;
uint32_t server_addr_size;
uint32_t cfg_seq_num;
- sock_test_socket_t ctrl_socket;
- sock_test_socket_t *test_socket;
+ vcl_test_session_t ctrl_socket;
+ vcl_test_session_t *test_socket;
uint32_t num_test_sockets;
uint8_t dump_cfg;
} sock_client_main_t;
@@ -48,21 +48,21 @@
static int
-sock_test_cfg_sync (sock_test_socket_t * socket)
+sock_test_cfg_sync (vcl_test_session_t * socket)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- sock_test_cfg_t *rl_cfg = (sock_test_cfg_t *) socket->rxbuf;
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ vcl_test_cfg_t *rl_cfg = (vcl_test_cfg_t *) socket->rxbuf;
int rx_bytes, tx_bytes;
if (socket->cfg.verbose)
- sock_test_cfg_dump (&socket->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&socket->cfg, 1 /* is_client */ );
ctrl->cfg.seq_num = ++scm->cfg_seq_num;
if (socket->cfg.verbose)
{
printf ("CLIENT (fd %d): Sending config sent to server.\n", socket->fd);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
tx_bytes = sock_test_write (socket->fd, (uint8_t *) & ctrl->cfg,
sizeof (ctrl->cfg), NULL, ctrl->cfg.verbose);
@@ -74,39 +74,39 @@
}
rx_bytes = sock_test_read (socket->fd, (uint8_t *) socket->rxbuf,
- sizeof (sock_test_cfg_t), NULL);
+ sizeof (vcl_test_cfg_t), NULL);
if (rx_bytes < 0)
return rx_bytes;
- if (rl_cfg->magic != SOCK_TEST_CFG_CTRL_MAGIC)
+ if (rl_cfg->magic != VCL_TEST_CFG_CTRL_MAGIC)
{
fprintf (stderr, "CLIENT (fd %d): ERROR: Bad server reply cfg "
"-- aborting!\n", socket->fd);
return -1;
}
- if ((rx_bytes != sizeof (sock_test_cfg_t))
- || !sock_test_cfg_verify (rl_cfg, &ctrl->cfg))
+ if ((rx_bytes != sizeof (vcl_test_cfg_t))
+ || !vcl_test_cfg_verify (rl_cfg, &ctrl->cfg))
{
fprintf (stderr, "CLIENT (fd %d): ERROR: Invalid config received "
"from server!\n", socket->fd);
- if (rx_bytes != sizeof (sock_test_cfg_t))
+ if (rx_bytes != sizeof (vcl_test_cfg_t))
{
fprintf (stderr, "\tRx bytes %d != cfg size %lu\n",
- rx_bytes, sizeof (sock_test_cfg_t));
+ rx_bytes, sizeof (vcl_test_cfg_t));
}
else
{
- sock_test_cfg_dump (rl_cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ );
fprintf (stderr, "CLIENT (fd %d): Valid config sent to server.\n",
socket->fd);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
return -1;
}
else if (socket->cfg.verbose)
{
printf ("CLIENT (fd %d): Got config back from server.\n", socket->fd);
- sock_test_cfg_dump (rl_cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (rl_cfg, 1 /* is_client */ );
}
ctrl->cfg.ctrl_handle = ((ctrl->cfg.ctrl_handle == ~0) ?
rl_cfg->ctrl_handle : ctrl->cfg.ctrl_handle);
@@ -118,8 +118,8 @@
echo_test_client ()
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ vcl_test_session_t *tsock;
int rx_bytes, tx_bytes, nbytes;
uint32_t i, n;
int rv;
@@ -132,11 +132,11 @@
FD_ZERO (&rd_fdset);
memset (&ctrl->stats, 0, sizeof (ctrl->stats));
ctrl->cfg.total_bytes = nbytes = strlen (ctrl->txbuf) + 1;
- for (n = 0; n != ctrl->cfg.num_test_sockets; n++)
+ for (n = 0; n != ctrl->cfg.num_test_sessions; n++)
{
tsock = &scm->test_socket[n];
tsock->cfg = ctrl->cfg;
- sock_test_socket_buf_alloc (tsock);
+ vcl_test_session_buf_alloc (tsock);
if (sock_test_cfg_sync (tsock))
return;
@@ -176,7 +176,7 @@
else if (rv == 0)
continue;
- for (i = 0; i < ctrl->cfg.num_test_sockets; i++)
+ for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
{
tsock = &scm->test_socket[i];
if (!((tsock->stats.stop.tv_sec == 0) &&
@@ -316,7 +316,7 @@
}
#endif
- for (i = 0; i < ctrl->cfg.num_test_sockets; i++)
+ for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
{
tsock = &scm->test_socket[i];
tsock->stats.start = ctrl->stats.start;
@@ -326,31 +326,31 @@
static char buf[64];
sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
- sock_test_stats_dump (buf, &tsock->stats,
- 1 /* show_rx */ , 1 /* show tx */ ,
- ctrl->cfg.verbose);
+ vcl_test_stats_dump (buf, &tsock->stats,
+ 1 /* show_rx */ , 1 /* show tx */ ,
+ ctrl->cfg.verbose);
}
- sock_test_stats_accumulate (&ctrl->stats, &tsock->stats);
+ vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats);
}
if (ctrl->cfg.verbose)
{
- sock_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
- 1 /* show_rx */ , 1 /* show tx */ ,
- ctrl->cfg.verbose);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
+ 1 /* show_rx */ , 1 /* show tx */ ,
+ ctrl->cfg.verbose);
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
if (ctrl->cfg.verbose > 1)
{
printf (" ctrl socket info\n"
- SOCK_TEST_SEPARATOR_STRING
+ VCL_TEST_SEPARATOR_STRING
" fd: %d (0x%08x)\n"
" rxbuf: %p\n"
" rxbuf size: %u (0x%08x)\n"
" txbuf: %p\n"
" txbuf size: %u (0x%08x)\n"
- SOCK_TEST_SEPARATOR_STRING,
+ VCL_TEST_SEPARATOR_STRING,
ctrl->fd, (uint32_t) ctrl->fd,
ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size,
ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size);
@@ -359,18 +359,18 @@
}
static void
-stream_test_client (sock_test_t test)
+stream_test_client (vcl_test_t test)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ vcl_test_session_t *tsock;
int tx_bytes;
uint32_t i, n;
int rv;
int nfds = 0;
fd_set wr_fdset, rd_fdset;
fd_set _wfdset, *wfdset = &_wfdset;
- fd_set _rfdset, *rfdset = (test == SOCK_TEST_TYPE_BI) ? &_rfdset : 0;
+ fd_set _rfdset, *rfdset = (test == VCL_TEST_TYPE_BI) ? &_rfdset : 0;
ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
ctrl->cfg.ctrl_handle = ~0;
@@ -378,7 +378,7 @@
printf ("\n" SOCK_TEST_BANNER_STRING
"CLIENT (fd %d): %s-directional Stream Test!\n\n"
"CLIENT (fd %d): Sending config to server on ctrl socket...\n",
- ctrl->fd, test == SOCK_TEST_TYPE_BI ? "Bi" : "Uni", ctrl->fd);
+ ctrl->fd, test == VCL_TEST_TYPE_BI ? "Bi" : "Uni", ctrl->fd);
if (sock_test_cfg_sync (ctrl))
{
@@ -389,11 +389,11 @@
FD_ZERO (&wr_fdset);
FD_ZERO (&rd_fdset);
memset (&ctrl->stats, 0, sizeof (ctrl->stats));
- for (n = 0; n != ctrl->cfg.num_test_sockets; n++)
+ for (n = 0; n != ctrl->cfg.num_test_sessions; n++)
{
tsock = &scm->test_socket[n];
tsock->cfg = ctrl->cfg;
- sock_test_socket_buf_alloc (tsock);
+ vcl_test_session_buf_alloc (tsock);
printf ("CLIENT (fd %d): Sending config to server on "
"test socket %d...\n", tsock->fd, n);
sock_test_cfg_sync (tsock);
@@ -436,14 +436,14 @@
else if (rv == 0)
continue;
- for (i = 0; i < ctrl->cfg.num_test_sockets; i++)
+ for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
{
tsock = &scm->test_socket[i];
if (!((tsock->stats.stop.tv_sec == 0) &&
(tsock->stats.stop.tv_nsec == 0)))
continue;
- if ((test == SOCK_TEST_TYPE_BI) &&
+ if ((test == VCL_TEST_TYPE_BI) &&
FD_ISSET (tsock->fd, rfdset) &&
(tsock->stats.rx_bytes < ctrl->cfg.total_bytes))
{
@@ -466,9 +466,9 @@
}
}
- if (((test == SOCK_TEST_TYPE_UNI) &&
+ if (((test == VCL_TEST_TYPE_UNI) &&
(tsock->stats.tx_bytes >= ctrl->cfg.total_bytes)) ||
- ((test == SOCK_TEST_TYPE_BI) &&
+ ((test == VCL_TEST_TYPE_BI) &&
(tsock->stats.rx_bytes >= ctrl->cfg.total_bytes)))
{
clock_gettime (CLOCK_REALTIME, &tsock->stats.stop);
@@ -487,7 +487,7 @@
return;
}
- for (i = 0; i < ctrl->cfg.num_test_sockets; i++)
+ for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
{
tsock = &scm->test_socket[i];
@@ -496,77 +496,77 @@
static char buf[64];
sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
- sock_test_stats_dump (buf, &tsock->stats,
- test == SOCK_TEST_TYPE_BI /* show_rx */ ,
- 1 /* show tx */ , ctrl->cfg.verbose);
+ vcl_test_stats_dump (buf, &tsock->stats,
+ test == VCL_TEST_TYPE_BI /* show_rx */ ,
+ 1 /* show tx */ , ctrl->cfg.verbose);
}
- sock_test_stats_accumulate (&ctrl->stats, &tsock->stats);
+ vcl_test_stats_accumulate (&ctrl->stats, &tsock->stats);
}
- sock_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
- test == SOCK_TEST_TYPE_BI /* show_rx */ ,
- 1 /* show tx */ , ctrl->cfg.verbose);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
+ test == VCL_TEST_TYPE_BI /* show_rx */ ,
+ 1 /* show tx */ , ctrl->cfg.verbose);
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
if (ctrl->cfg.verbose)
{
printf (" ctrl socket info\n"
- SOCK_TEST_SEPARATOR_STRING
+ VCL_TEST_SEPARATOR_STRING
" fd: %d (0x%08x)\n"
" rxbuf: %p\n"
" rxbuf size: %u (0x%08x)\n"
" txbuf: %p\n"
" txbuf size: %u (0x%08x)\n"
- SOCK_TEST_SEPARATOR_STRING,
+ VCL_TEST_SEPARATOR_STRING,
ctrl->fd, (uint32_t) ctrl->fd,
ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size,
ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size);
}
- ctrl->cfg.test = SOCK_TEST_TYPE_ECHO;
+ ctrl->cfg.test = VCL_TEST_TYPE_ECHO;
if (sock_test_cfg_sync (ctrl))
fprintf (stderr, "CLIENT: ERROR: post-test cfg sync failed!");
printf ("CLIENT (fd %d): %s-directional Stream Test Complete!\n"
SOCK_TEST_BANNER_STRING "\n", ctrl->fd,
- test == SOCK_TEST_TYPE_BI ? "Bi" : "Uni");
+ test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
}
static void
exit_client (void)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ vcl_test_session_t *tsock;
int i;
#ifndef VCL_TEST
printf ("CLIENT: af_unix_echo_tx %d, af_unix_echo_rx %d\n",
scm->af_unix_echo_tx, scm->af_unix_echo_rx);
#endif
- for (i = 0; i < ctrl->cfg.num_test_sockets; i++)
+ for (i = 0; i < ctrl->cfg.num_test_sessions; i++)
{
tsock = &scm->test_socket[i];
- tsock->cfg.test = SOCK_TEST_TYPE_EXIT;
+ tsock->cfg.test = VCL_TEST_TYPE_EXIT;
/* coverity[COPY_PASTE_ERROR] */
if (ctrl->cfg.verbose)
{
printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n",
tsock->fd);
- sock_test_cfg_dump (&tsock->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&tsock->cfg, 1 /* is_client */ );
}
(void) sock_test_write (tsock->fd, (uint8_t *) & tsock->cfg,
sizeof (tsock->cfg), &tsock->stats,
ctrl->cfg.verbose);
}
- ctrl->cfg.test = SOCK_TEST_TYPE_EXIT;
+ ctrl->cfg.test = VCL_TEST_TYPE_EXIT;
if (ctrl->cfg.verbose)
{
printf ("\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->fd);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
(void) sock_test_write (ctrl->fd, (uint8_t *) & ctrl->cfg,
sizeof (ctrl->cfg), &ctrl->stats,
@@ -579,8 +579,8 @@
sock_test_connect_test_sockets (uint32_t num_test_sockets)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ vcl_test_session_t *tsock;
int i, rv, errno_val;
if (num_test_sockets < 1)
@@ -607,7 +607,7 @@
else if (num_test_sockets > scm->num_test_sockets)
{
tsock = realloc (scm->test_socket,
- sizeof (sock_test_socket_t) * num_test_sockets);
+ sizeof (vcl_test_session_t) * num_test_sockets);
if (!tsock)
{
errno_val = errno;
@@ -669,7 +669,7 @@
return -1;
}
tsock->cfg = ctrl->cfg;
- sock_test_socket_buf_alloc (tsock);
+ vcl_test_session_buf_alloc (tsock);
sock_test_cfg_sync (tsock);
printf ("CLIENT (fd %d): Test socket %d connected.\n",
@@ -688,23 +688,23 @@
#define INDENT "\n "
printf ("CLIENT: Test configuration commands:"
- INDENT SOCK_TEST_TOKEN_HELP
+ INDENT VCL_TEST_TOKEN_HELP
"\t\t\tDisplay help."
- INDENT SOCK_TEST_TOKEN_EXIT
+ INDENT VCL_TEST_TOKEN_EXIT
"\t\t\tExit test client & server."
- INDENT SOCK_TEST_TOKEN_SHOW_CFG
+ INDENT VCL_TEST_TOKEN_SHOW_CFG
"\t\t\tShow the current test cfg."
- INDENT SOCK_TEST_TOKEN_RUN_UNI
+ INDENT VCL_TEST_TOKEN_RUN_UNI
"\t\t\tRun the Uni-directional test."
- INDENT SOCK_TEST_TOKEN_RUN_BI
+ INDENT VCL_TEST_TOKEN_RUN_BI
"\t\t\tRun the Bi-directional test."
- INDENT SOCK_TEST_TOKEN_VERBOSE
+ INDENT VCL_TEST_TOKEN_VERBOSE
"\t\t\tToggle verbose setting."
- INDENT SOCK_TEST_TOKEN_RXBUF_SIZE
+ INDENT VCL_TEST_TOKEN_RXBUF_SIZE
"<rxbuf size>\tRx buffer size (bytes)."
- INDENT SOCK_TEST_TOKEN_TXBUF_SIZE
+ INDENT VCL_TEST_TOKEN_TXBUF_SIZE
"<txbuf size>\tTx buffer size (bytes)."
- INDENT SOCK_TEST_TOKEN_NUM_WRITES
+ INDENT VCL_TEST_TOKEN_NUM_WRITES
"<# of writes>\tNumber of txbuf writes to server." "\n");
}
@@ -712,37 +712,37 @@
cfg_txbuf_size_set (void)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- char *p = ctrl->txbuf + strlen (SOCK_TEST_TOKEN_TXBUF_SIZE);
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_TXBUF_SIZE);
uint64_t txbuf_size = strtoull ((const char *) p, NULL, 10);
- if (txbuf_size >= SOCK_TEST_CFG_BUF_SIZE_MIN)
+ if (txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
{
ctrl->cfg.txbuf_size = txbuf_size;
ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
- sock_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
- (uint8_t **) & ctrl->txbuf, &ctrl->txbuf_size);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
+ (uint8_t **) & ctrl->txbuf, &ctrl->txbuf_size);
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
else
fprintf (stderr, "CLIENT: ERROR: Invalid txbuf size (%lu) < "
"minimum buf size (%u)!\n",
- txbuf_size, SOCK_TEST_CFG_BUF_SIZE_MIN);
+ txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
}
static void
cfg_num_writes_set (void)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- char *p = ctrl->txbuf + strlen (SOCK_TEST_TOKEN_NUM_WRITES);
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_WRITES);
uint32_t num_writes = strtoul ((const char *) p, NULL, 10);
if (num_writes > 0)
{
ctrl->cfg.num_writes = num_writes;
ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
else
{
@@ -754,23 +754,23 @@
cfg_num_test_sockets_set (void)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- char *p = ctrl->txbuf + strlen (SOCK_TEST_TOKEN_NUM_TEST_SCKTS);
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_TEST_SESS);
uint32_t num_test_sockets = strtoul ((const char *) p, NULL, 10);
if ((num_test_sockets > 0) &&
- (num_test_sockets <= SOCK_TEST_CFG_MAX_TEST_SCKTS))
+ (num_test_sockets <= VCL_TEST_CFG_MAX_TEST_SESS))
{
- ctrl->cfg.num_test_sockets = num_test_sockets;
+ ctrl->cfg.num_test_sessions = num_test_sockets;
sock_test_connect_test_sockets (num_test_sockets);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
else
{
fprintf (stderr, "CLIENT: ERROR: invalid num test sockets: "
"%u, (%d max)\n",
- num_test_sockets, SOCK_TEST_CFG_MAX_TEST_SCKTS);
+ num_test_sockets, VCL_TEST_CFG_MAX_TEST_SESS);
}
}
@@ -778,83 +778,83 @@
cfg_rxbuf_size_set (void)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- char *p = ctrl->txbuf + strlen (SOCK_TEST_TOKEN_RXBUF_SIZE);
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_RXBUF_SIZE);
uint64_t rxbuf_size = strtoull ((const char *) p, NULL, 10);
- if (rxbuf_size >= SOCK_TEST_CFG_BUF_SIZE_MIN)
+ if (rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
{
ctrl->cfg.rxbuf_size = rxbuf_size;
- sock_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
- (uint8_t **) & ctrl->rxbuf, &ctrl->rxbuf_size);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
+ (uint8_t **) & ctrl->rxbuf, &ctrl->rxbuf_size);
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
else
fprintf (stderr, "CLIENT: ERROR: Invalid rxbuf size (%lu) < "
"minimum buf size (%u)!\n",
- rxbuf_size, SOCK_TEST_CFG_BUF_SIZE_MIN);
+ rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
}
static void
cfg_verbose_toggle (void)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
ctrl->cfg.verbose = ctrl->cfg.verbose ? 0 : 1;
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
-static sock_test_t
+static vcl_test_t
parse_input ()
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
- sock_test_t rv = SOCK_TEST_TYPE_NONE;
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
+ vcl_test_t rv = VCL_TEST_TYPE_NONE;
- if (!strncmp (SOCK_TEST_TOKEN_EXIT, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_EXIT)))
- rv = SOCK_TEST_TYPE_EXIT;
+ if (!strncmp (VCL_TEST_TOKEN_EXIT, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_EXIT)))
+ rv = VCL_TEST_TYPE_EXIT;
- else if (!strncmp (SOCK_TEST_TOKEN_HELP, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_HELP)))
+ else if (!strncmp (VCL_TEST_TOKEN_HELP, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_HELP)))
dump_help ();
- else if (!strncmp (SOCK_TEST_TOKEN_SHOW_CFG, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_SHOW_CFG)))
+ else if (!strncmp (VCL_TEST_TOKEN_SHOW_CFG, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_SHOW_CFG)))
scm->dump_cfg = 1;
- else if (!strncmp (SOCK_TEST_TOKEN_VERBOSE, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_VERBOSE)))
+ else if (!strncmp (VCL_TEST_TOKEN_VERBOSE, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_VERBOSE)))
cfg_verbose_toggle ();
- else if (!strncmp (SOCK_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_TXBUF_SIZE)))
+ else if (!strncmp (VCL_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_TXBUF_SIZE)))
cfg_txbuf_size_set ();
- else if (!strncmp (SOCK_TEST_TOKEN_NUM_TEST_SCKTS, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_NUM_TEST_SCKTS)))
+ else if (!strncmp (VCL_TEST_TOKEN_NUM_TEST_SESS, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_NUM_TEST_SESS)))
cfg_num_test_sockets_set ();
- else if (!strncmp (SOCK_TEST_TOKEN_NUM_WRITES, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_NUM_WRITES)))
+ else if (!strncmp (VCL_TEST_TOKEN_NUM_WRITES, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_NUM_WRITES)))
cfg_num_writes_set ();
- else if (!strncmp (SOCK_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_RXBUF_SIZE)))
+ else if (!strncmp (VCL_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_RXBUF_SIZE)))
cfg_rxbuf_size_set ();
- else if (!strncmp (SOCK_TEST_TOKEN_RUN_UNI, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_RUN_UNI)))
- rv = ctrl->cfg.test = SOCK_TEST_TYPE_UNI;
+ else if (!strncmp (VCL_TEST_TOKEN_RUN_UNI, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_RUN_UNI)))
+ rv = ctrl->cfg.test = VCL_TEST_TYPE_UNI;
- else if (!strncmp (SOCK_TEST_TOKEN_RUN_BI, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_RUN_BI)))
- rv = ctrl->cfg.test = SOCK_TEST_TYPE_BI;
+ else if (!strncmp (VCL_TEST_TOKEN_RUN_BI, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_RUN_BI)))
+ rv = ctrl->cfg.test = VCL_TEST_TYPE_BI;
else
- rv = SOCK_TEST_TYPE_ECHO;
+ rv = VCL_TEST_TYPE_ECHO;
return rv;
}
@@ -885,12 +885,12 @@
main (int argc, char **argv)
{
sock_client_main_t *scm = &vcl_client_main;
- sock_test_socket_t *ctrl = &scm->ctrl_socket;
+ vcl_test_session_t *ctrl = &scm->ctrl_socket;
int c, rv, errno_val;
- sock_test_t post_test = SOCK_TEST_TYPE_NONE;
+ vcl_test_t post_test = VCL_TEST_TYPE_NONE;
- sock_test_cfg_init (&ctrl->cfg);
- sock_test_socket_buf_alloc (ctrl);
+ vcl_test_cfg_init (&ctrl->cfg);
+ vcl_test_session_buf_alloc (ctrl);
opterr = 0;
while ((c = getopt (argc, argv, "chn:w:XE:I:N:R:T:UBV6D")) != -1)
@@ -901,20 +901,20 @@
break;
case 's':
- if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sockets) != 1)
- if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sockets) != 1)
+ if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1)
+ if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sessions) != 1)
{
fprintf (stderr, "CLIENT: ERROR: Invalid value for "
"option -%c!\n", c);
print_usage_and_exit ();
}
- if (!ctrl->cfg.num_test_sockets ||
- (ctrl->cfg.num_test_sockets > FD_SETSIZE))
+ if (!ctrl->cfg.num_test_sessions ||
+ (ctrl->cfg.num_test_sessions > FD_SETSIZE))
{
fprintf (stderr, "CLIENT: ERROR: Invalid number of "
"sockets (%d) specified for option -%c!\n"
" Valid range is 1 - %d\n",
- ctrl->cfg.num_test_sockets, c, FD_SETSIZE);
+ ctrl->cfg.num_test_sessions, c, FD_SETSIZE);
print_usage_and_exit ();
}
break;
@@ -924,7 +924,7 @@
break;
case 'X':
- post_test = SOCK_TEST_TYPE_EXIT;
+ post_test = VCL_TEST_TYPE_EXIT;
break;
case 'E':
@@ -936,22 +936,21 @@
print_usage_and_exit ();
}
strcpy (ctrl->txbuf, optarg);
- ctrl->cfg.test = SOCK_TEST_TYPE_ECHO;
+ ctrl->cfg.test = VCL_TEST_TYPE_ECHO;
break;
case 'I':
- if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sockets) != 1)
- if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sockets) != 1)
+ if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1)
+ if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sessions) != 1)
{
fprintf (stderr, "CLIENT: ERROR: Invalid value for "
"option -%c!\n", c);
print_usage_and_exit ();
}
- if (ctrl->cfg.num_test_sockets > SOCK_TEST_CFG_MAX_TEST_SCKTS)
+ if (ctrl->cfg.num_test_sessions > VCL_TEST_CFG_MAX_TEST_SESS)
{
fprintf (stderr, "CLIENT: ERROR: value greater than max "
- "number test sockets (%d)!",
- SOCK_TEST_CFG_MAX_TEST_SCKTS);
+ "number test sockets (%d)!", VCL_TEST_CFG_MAX_TEST_SESS);
print_usage_and_exit ();
}
break;
@@ -975,18 +974,18 @@
"option -%c!\n", c);
print_usage_and_exit ();
}
- if (ctrl->cfg.rxbuf_size >= SOCK_TEST_CFG_BUF_SIZE_MIN)
+ if (ctrl->cfg.rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
{
ctrl->rxbuf_size = ctrl->cfg.rxbuf_size;
- sock_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
- (uint8_t **) & ctrl->rxbuf,
- &ctrl->rxbuf_size);
+ vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
+ (uint8_t **) & ctrl->rxbuf,
+ &ctrl->rxbuf_size);
}
else
{
fprintf (stderr, "CLIENT: ERROR: rxbuf size (%lu) "
"less than minumum (%u)\n",
- ctrl->cfg.rxbuf_size, SOCK_TEST_CFG_BUF_SIZE_MIN);
+ ctrl->cfg.rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
print_usage_and_exit ();
}
@@ -1000,12 +999,12 @@
"for option -%c!\n", c);
print_usage_and_exit ();
}
- if (ctrl->cfg.txbuf_size >= SOCK_TEST_CFG_BUF_SIZE_MIN)
+ if (ctrl->cfg.txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
{
ctrl->txbuf_size = ctrl->cfg.txbuf_size;
- sock_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
- (uint8_t **) & ctrl->txbuf,
- &ctrl->txbuf_size);
+ vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
+ (uint8_t **) & ctrl->txbuf,
+ &ctrl->txbuf_size);
ctrl->cfg.total_bytes =
ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
}
@@ -1013,17 +1012,17 @@
{
fprintf (stderr, "CLIENT: ERROR: txbuf size (%lu) "
"less than minumum (%u)!\n",
- ctrl->cfg.txbuf_size, SOCK_TEST_CFG_BUF_SIZE_MIN);
+ ctrl->cfg.txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
print_usage_and_exit ();
}
break;
case 'U':
- ctrl->cfg.test = SOCK_TEST_TYPE_UNI;
+ ctrl->cfg.test = VCL_TEST_TYPE_UNI;
break;
case 'B':
- ctrl->cfg.test = SOCK_TEST_TYPE_BI;
+ ctrl->cfg.test = VCL_TEST_TYPE_BI;
break;
case 'V':
@@ -1173,56 +1172,56 @@
}
while (rv < 0);
- sock_test_connect_test_sockets (ctrl->cfg.num_test_sockets);
+ sock_test_connect_test_sockets (ctrl->cfg.num_test_sessions);
- while (ctrl->cfg.test != SOCK_TEST_TYPE_EXIT)
+ while (ctrl->cfg.test != VCL_TEST_TYPE_EXIT)
{
if (scm->dump_cfg)
{
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
scm->dump_cfg = 0;
}
switch (ctrl->cfg.test)
{
- case SOCK_TEST_TYPE_ECHO:
+ case VCL_TEST_TYPE_ECHO:
echo_test_client ();
break;
- case SOCK_TEST_TYPE_UNI:
- case SOCK_TEST_TYPE_BI:
+ case VCL_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
stream_test_client (ctrl->cfg.test);
break;
- case SOCK_TEST_TYPE_EXIT:
+ case VCL_TEST_TYPE_EXIT:
continue;
- case SOCK_TEST_TYPE_NONE:
+ case VCL_TEST_TYPE_NONE:
default:
break;
}
switch (post_test)
{
- case SOCK_TEST_TYPE_EXIT:
+ case VCL_TEST_TYPE_EXIT:
switch (ctrl->cfg.test)
{
- case SOCK_TEST_TYPE_EXIT:
- case SOCK_TEST_TYPE_UNI:
- case SOCK_TEST_TYPE_BI:
- case SOCK_TEST_TYPE_ECHO:
- ctrl->cfg.test = SOCK_TEST_TYPE_EXIT;
+ case VCL_TEST_TYPE_EXIT:
+ case VCL_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
+ case VCL_TEST_TYPE_ECHO:
+ ctrl->cfg.test = VCL_TEST_TYPE_EXIT;
continue;
- case SOCK_TEST_TYPE_NONE:
+ case VCL_TEST_TYPE_NONE:
default:
break;
}
break;
- case SOCK_TEST_TYPE_NONE:
- case SOCK_TEST_TYPE_ECHO:
- case SOCK_TEST_TYPE_UNI:
- case SOCK_TEST_TYPE_BI:
+ case VCL_TEST_TYPE_NONE:
+ case VCL_TEST_TYPE_ECHO:
+ case VCL_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
default:
break;
}
@@ -1231,7 +1230,7 @@
memset (ctrl->rxbuf, 0, ctrl->rxbuf_size);
printf ("\nCLIENT: Type some characters and hit <return>\n"
- "('" SOCK_TEST_TOKEN_HELP "' for help): ");
+ "('" VCL_TEST_TOKEN_HELP "' for help): ");
if (fgets (ctrl->txbuf, ctrl->txbuf_size, stdin) != NULL)
{
diff --git a/src/vcl/sock_test_common.h b/src/vcl/sock_test_common.h
deleted file mode 100644
index 3355397..0000000
--- a/src/vcl/sock_test_common.h
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright (c) 2018 Cisco and/or its affiliates.
- * 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.
- */
-
-#ifndef __sock_test_common_h__
-#define __sock_test_common_h__
-
-#include <netdb.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define SOCK_TEST_TOKEN_HELP "#H"
-#define SOCK_TEST_TOKEN_EXIT "#X"
-#define SOCK_TEST_TOKEN_VERBOSE "#V"
-#define SOCK_TEST_TOKEN_TXBUF_SIZE "#T:"
-#define SOCK_TEST_TOKEN_NUM_TEST_SCKTS "#I:"
-#define SOCK_TEST_TOKEN_NUM_WRITES "#N:"
-#define SOCK_TEST_TOKEN_RXBUF_SIZE "#R:"
-#define SOCK_TEST_TOKEN_SHOW_CFG "#C"
-#define SOCK_TEST_TOKEN_RUN_UNI "#U"
-#define SOCK_TEST_TOKEN_RUN_BI "#B"
-
-#define SOCK_TEST_BANNER_STRING \
- "============================================\n"
-#define SOCK_TEST_SEPARATOR_STRING \
- " -----------------------------\n"
-
-#define ONE_GIG (1024*1024*1024)
-#define SOCK_TEST_SERVER_PORT 22000
-#define SOCK_TEST_LOCALHOST_IPADDR "127.0.0.1"
-
-#define SOCK_TEST_CFG_CTRL_MAGIC 0xfeedface
-#define SOCK_TEST_CFG_NUM_WRITES_DEF 1000000
-#define SOCK_TEST_CFG_TXBUF_SIZE_DEF 8192
-#define SOCK_TEST_CFG_RXBUF_SIZE_DEF (64*SOCK_TEST_CFG_TXBUF_SIZE_DEF)
-#define SOCK_TEST_CFG_BUF_SIZE_MIN 128
-#define SOCK_TEST_CFG_MAX_TEST_SCKTS 32
-
-typedef enum
-{
- SOCK_TEST_TYPE_NONE,
- SOCK_TEST_TYPE_ECHO,
- SOCK_TEST_TYPE_UNI,
- SOCK_TEST_TYPE_BI,
- SOCK_TEST_TYPE_EXIT,
-} sock_test_t;
-
-typedef struct __attribute__ ((packed))
-{
- uint32_t magic;
- uint32_t seq_num;
- uint32_t test;
- uint32_t ctrl_handle;
- uint32_t num_test_sockets;
- uint32_t verbose;
- uint32_t address_ip6;
- uint32_t transport_udp;
- uint64_t rxbuf_size;
- uint64_t txbuf_size;
- uint64_t num_writes;
- uint64_t total_bytes;
-} sock_test_cfg_t;
-
-typedef struct
-{
- uint64_t rx_xacts;
- uint64_t rx_bytes;
- uint32_t rx_eagain;
- uint32_t rx_incomp;
- uint64_t tx_xacts;
- uint64_t tx_bytes;
- uint32_t tx_eagain;
- uint32_t tx_incomp;
- struct timespec start;
- struct timespec stop;
-} sock_test_stats_t;
-
-typedef struct
-{
- int fd;
- uint32_t txbuf_size;
- char *txbuf;
- uint32_t rxbuf_size;
- char *rxbuf;
- sock_test_cfg_t cfg;
- sock_test_stats_t stats;
-} sock_test_socket_t;
-
-static inline void
-sock_test_stats_accumulate (sock_test_stats_t * accum,
- sock_test_stats_t * incr)
-{
- accum->rx_xacts += incr->rx_xacts;
- accum->rx_bytes += incr->rx_bytes;
- accum->rx_eagain += incr->rx_eagain;
- accum->rx_incomp += incr->rx_incomp;
- accum->tx_xacts += incr->tx_xacts;
- accum->tx_bytes += incr->tx_bytes;
- accum->tx_eagain += incr->tx_eagain;
- accum->tx_incomp += incr->tx_incomp;
-}
-
-static inline void
-sock_test_cfg_init (sock_test_cfg_t *cfg)
-{
- cfg->magic = SOCK_TEST_CFG_CTRL_MAGIC;
- cfg->test = SOCK_TEST_TYPE_NONE;
- cfg->ctrl_handle = ~0;
- cfg->num_test_sockets = 1;
- cfg->verbose = 0;
- cfg->rxbuf_size = SOCK_TEST_CFG_RXBUF_SIZE_DEF;
- cfg->num_writes = SOCK_TEST_CFG_NUM_WRITES_DEF;
- cfg->txbuf_size = SOCK_TEST_CFG_TXBUF_SIZE_DEF;
- cfg->total_bytes = cfg->num_writes * cfg->txbuf_size;
-}
-
-static inline int
-sock_test_cfg_verify (sock_test_cfg_t *cfg, sock_test_cfg_t *valid_cfg)
-{
- /* Note: txbuf & rxbuf on server are the same buffer,
- * so txbuf_size is not included in this check.
- */
- return ((cfg->magic == valid_cfg->magic)
- && (cfg->test == valid_cfg->test)
- && (cfg->verbose == valid_cfg->verbose)
- && (cfg->rxbuf_size == valid_cfg->rxbuf_size)
- && (cfg->num_writes == valid_cfg->num_writes)
- && (cfg->total_bytes == valid_cfg->total_bytes));
-}
-
-static inline void
-sock_test_buf_alloc (sock_test_cfg_t *cfg, uint8_t is_rxbuf, uint8_t **buf,
- uint32_t *bufsize)
-{
- uint32_t alloc_size = is_rxbuf ? cfg->rxbuf_size : cfg->txbuf_size;
- uint8_t *lb = realloc (*buf, (size_t) alloc_size);
-
- if (lb)
- {
- if (is_rxbuf)
- cfg->rxbuf_size = *bufsize = alloc_size;
- else
- cfg->txbuf_size = *bufsize = alloc_size;
-
- *buf = lb;
- }
- else
- {
- int errno_val = errno;
- perror ("ERROR in sock_test_buf_alloc()");
- fprintf (stderr, "SOCK_TEST: ERROR: Buffer allocation "
- "failed (errno = %d)!\n"
- " Using buffer size %d instead of desired"
- " size (%d)\n", errno_val, *bufsize, alloc_size);
- }
-}
-
-static inline void
-sock_test_socket_buf_alloc (sock_test_socket_t *socket)
-{
- socket->rxbuf_size = socket->cfg.rxbuf_size;
- socket->txbuf_size = socket->cfg.txbuf_size;
- sock_test_buf_alloc (&socket->cfg, 0 /* is_rxbuf */ ,
- (uint8_t **) &socket->txbuf, &socket->txbuf_size);
- sock_test_buf_alloc (&socket->cfg, 1 /* is_rxbuf */ ,
- (uint8_t **) &socket->rxbuf, &socket->rxbuf_size);
-}
-
-static inline char *
-sock_test_type_str (sock_test_t t)
-{
- switch (t)
- {
- case SOCK_TEST_TYPE_NONE:
- return "NONE";
-
- case SOCK_TEST_TYPE_ECHO:
- return "ECHO";
-
- case SOCK_TEST_TYPE_UNI:
- return "UNI";
-
- case SOCK_TEST_TYPE_BI:
- return "BI";
-
- case SOCK_TEST_TYPE_EXIT:
- return "EXIT";
-
- default:
- return "Unknown";
- }
-}
-
-static inline void
-sock_test_cfg_dump (sock_test_cfg_t * cfg, uint8_t is_client)
-{
- char *spc = " ";
-
- printf (" test config (%p):\n"
- SOCK_TEST_SEPARATOR_STRING
- " magic: 0x%08x\n"
- " seq_num: 0x%08x\n"
- "%-5s test: %s (%d)\n"
- " ctrl handle: %d (0x%x)\n"
- "%-5s num test sockets: %u (0x%08x)\n"
- "%-5s verbose: %s (%d)\n"
- "%-5s rxbuf size: %lu (0x%08lx)\n"
- "%-5s txbuf size: %lu (0x%08lx)\n"
- "%-5s num writes: %lu (0x%08lx)\n"
- " client tx bytes: %lu (0x%08lx)\n"
- SOCK_TEST_SEPARATOR_STRING,
- (void *) cfg, cfg->magic, cfg->seq_num,
- is_client && (cfg->test == SOCK_TEST_TYPE_UNI) ?
- "'"SOCK_TEST_TOKEN_RUN_UNI"'" :
- is_client && (cfg->test == SOCK_TEST_TYPE_BI) ?
- "'"SOCK_TEST_TOKEN_RUN_BI"'" : spc,
- sock_test_type_str (cfg->test), cfg->test,
- cfg->ctrl_handle, cfg->ctrl_handle,
- is_client ? "'"SOCK_TEST_TOKEN_NUM_TEST_SCKTS"'" : spc,
- cfg->num_test_sockets, cfg->num_test_sockets,
- is_client ? "'"SOCK_TEST_TOKEN_VERBOSE"'" : spc,
- cfg->verbose ? "on" : "off", cfg->verbose,
- is_client ? "'"SOCK_TEST_TOKEN_RXBUF_SIZE"'" : spc,
- cfg->rxbuf_size, cfg->rxbuf_size,
- is_client ? "'"SOCK_TEST_TOKEN_TXBUF_SIZE"'" : spc,
- cfg->txbuf_size, cfg->txbuf_size,
- is_client ? "'"SOCK_TEST_TOKEN_NUM_WRITES"'" : spc,
- cfg->num_writes, cfg->num_writes,
- cfg->total_bytes, cfg->total_bytes);
-}
-
-static inline void
-sock_test_stats_dump (char * header, sock_test_stats_t * stats,
- uint8_t show_rx, uint8_t show_tx,
- uint8_t verbose)
-{
- struct timespec diff;
- double duration, rate;
- uint64_t total_bytes;
-
- if ((stats->stop.tv_nsec - stats->start.tv_nsec) < 0)
- {
- diff.tv_sec = stats->stop.tv_sec - stats->start.tv_sec - 1;
- diff.tv_nsec = stats->stop.tv_nsec - stats->start.tv_nsec + 1e9;
- }
- else
- {
- diff.tv_sec = stats->stop.tv_sec - stats->start.tv_sec;
- diff.tv_nsec = stats->stop.tv_nsec - stats->start.tv_nsec;
- }
- duration = (double) diff.tv_sec + (1e-9 * diff.tv_nsec);
-
- total_bytes = stats->tx_bytes + stats->rx_bytes;
- rate = (double) total_bytes * 8 / duration / 1e9;
- printf ("\n%s: Streamed %lu bytes\n"
- " in %lf seconds (%lf Gbps %s-duplex)!\n",
- header, total_bytes, duration, rate,
- (show_rx && show_tx) ? "full" : "half");
-
- if (show_tx)
- {
- printf (SOCK_TEST_SEPARATOR_STRING
- " tx stats (0x%p):\n"
- SOCK_TEST_SEPARATOR_STRING
- " writes: %lu (0x%08lx)\n"
- " tx bytes: %lu (0x%08lx)\n"
- " tx eagain: %u (0x%08x)\n"
- " tx incomplete: %u (0x%08x)\n",
- (void *)stats, stats->tx_xacts, stats->tx_xacts,
- stats->tx_bytes, stats->tx_bytes,
- stats->tx_eagain, stats->tx_eagain,
- stats->tx_incomp, stats->tx_incomp);
- }
- if (show_rx)
- {
- printf (SOCK_TEST_SEPARATOR_STRING
- " rx stats (0x%p):\n"
- SOCK_TEST_SEPARATOR_STRING
- " reads: %lu (0x%08lx)\n"
- " rx bytes: %lu (0x%08lx)\n"
- " rx eagain: %u (0x%08x)\n"
- " rx incomplete: %u (0x%08x)\n",
- (void *)stats, stats->rx_xacts, stats->rx_xacts,
- stats->rx_bytes, stats->rx_bytes,
- stats->rx_eagain, stats->rx_eagain,
- stats->rx_incomp, stats->rx_incomp);
- }
- if (verbose)
- printf (" start.tv_sec: %ld\n"
- " start.tv_nsec: %ld\n"
- " stop.tv_sec: %ld\n"
- " stop.tv_nsec: %ld\n",
- stats->start.tv_sec, stats->start.tv_nsec,
- stats->stop.tv_sec, stats->stop.tv_nsec);
-
- printf (SOCK_TEST_SEPARATOR_STRING);
-}
-
-#endif /* __sock_test_common_h__ */
diff --git a/src/vcl/sock_test_server.c b/src/vcl/sock_test_server.c
index 896aeb0..11c667c 100644
--- a/src/vcl/sock_test_server.c
+++ b/src/vcl/sock_test_server.c
@@ -51,8 +51,8 @@
int fd;
uint8_t *buf;
uint32_t buf_size;
- sock_test_cfg_t cfg;
- sock_test_stats_t stats;
+ vcl_test_cfg_t cfg;
+ vcl_test_stats_t stats;
#ifdef VCL_TEST
vppcom_endpt_t endpt;
uint8_t ip[16];
@@ -144,9 +144,9 @@
{
sock_server_conn_t *conn = &conn_pool[i];
memset (conn, 0, sizeof (*conn));
- sock_test_cfg_init (&conn->cfg);
- sock_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
- &conn->buf, &conn->buf_size);
+ vcl_test_cfg_init (&conn->cfg);
+ vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
+ &conn->buf, &conn->buf_size);
conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
}
@@ -197,17 +197,17 @@
}
static inline void
-sync_config_and_reply (sock_server_conn_t * conn, sock_test_cfg_t * rx_cfg)
+sync_config_and_reply (sock_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
{
conn->cfg = *rx_cfg;
- sock_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
- &conn->buf, &conn->buf_size);
+ vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
+ &conn->buf, &conn->buf_size);
conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
if (conn->cfg.verbose)
{
printf ("\nSERVER (fd %d): Replying to cfg message!\n", conn->fd);
- sock_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
+ vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
}
(void) sock_test_write (conn->fd, (uint8_t *) & conn->cfg,
sizeof (conn->cfg), NULL, conn->cfg.verbose);
@@ -215,11 +215,11 @@
static void
stream_test_server_start_stop (sock_server_conn_t * conn,
- sock_test_cfg_t * rx_cfg)
+ vcl_test_cfg_t * rx_cfg)
{
sock_server_main_t *ssm = &sock_server_main;
int client_fd = conn->fd;
- sock_test_t test = rx_cfg->test;
+ vcl_test_t test = rx_cfg->test;
if (rx_cfg->ctrl_handle == conn->fd)
{
@@ -232,46 +232,46 @@
if (tc->cfg.ctrl_handle == conn->fd)
{
- sock_test_stats_accumulate (&conn->stats, &tc->stats);
+ vcl_test_stats_accumulate (&conn->stats, &tc->stats);
if (conn->cfg.verbose)
{
static char buf[64];
sprintf (buf, "SERVER (fd %d) RESULTS", tc->fd);
- sock_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
- test == SOCK_TEST_TYPE_BI
- /* show tx */ ,
- conn->cfg.verbose);
+ vcl_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
+ test == VCL_TEST_TYPE_BI
+ /* show tx */ ,
+ conn->cfg.verbose);
}
}
}
- sock_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
- (test == SOCK_TEST_TYPE_BI) /* show_tx */ ,
- conn->cfg.verbose);
- sock_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
+ vcl_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
+ (test == VCL_TEST_TYPE_BI) /* show_tx */ ,
+ conn->cfg.verbose);
+ vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
if (conn->cfg.verbose)
{
printf (" sock server main\n"
- SOCK_TEST_SEPARATOR_STRING
+ VCL_TEST_SEPARATOR_STRING
" buf: %p\n"
" buf size: %u (0x%08x)\n"
- SOCK_TEST_SEPARATOR_STRING,
+ VCL_TEST_SEPARATOR_STRING,
conn->buf, conn->buf_size, conn->buf_size);
}
sync_config_and_reply (conn, rx_cfg);
printf ("\nSERVER (fd %d): %s-directional Stream Test Complete!\n"
SOCK_TEST_BANNER_STRING "\n", conn->fd,
- test == SOCK_TEST_TYPE_BI ? "Bi" : "Uni");
+ test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
}
else
{
printf ("\n" SOCK_TEST_BANNER_STRING
"SERVER (fd %d): %s-directional Stream Test!\n"
" Sending client the test cfg to start streaming data...\n",
- client_fd, test == SOCK_TEST_TYPE_BI ? "Bi" : "Uni");
+ client_fd, test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
rx_cfg->ctrl_handle = (rx_cfg->ctrl_handle == ~0) ? conn->fd :
rx_cfg->ctrl_handle;
@@ -289,9 +289,9 @@
stream_test_server (sock_server_conn_t * conn, int rx_bytes)
{
int client_fd = conn->fd;
- sock_test_t test = conn->cfg.test;
+ vcl_test_t test = conn->cfg.test;
- if (test == SOCK_TEST_TYPE_BI)
+ if (test == VCL_TEST_TYPE_BI)
(void) sock_test_write (client_fd, conn->buf, rx_bytes, &conn->stats,
conn->cfg.verbose);
@@ -461,13 +461,13 @@
int client_fd, rv, main_rv = 0;
int tx_bytes, rx_bytes, nbytes;
sock_server_conn_t *conn;
- sock_test_cfg_t *rx_cfg;
+ vcl_test_cfg_t *rx_cfg;
uint32_t xtra = 0;
uint64_t xtra_bytes = 0;
struct sockaddr_storage servaddr;
int errno_val;
int c, v, i;
- uint16_t port = SOCK_TEST_SERVER_PORT;
+ uint16_t port = VCL_TEST_SERVER_PORT;
#if ! SOCK_SERVER_USE_EPOLL
fd_set _rfdset, *rfdset = &_rfdset;
#endif
@@ -834,14 +834,14 @@
conn->buf_size, &conn->stats);
if (rx_bytes > 0)
{
- rx_cfg = (sock_test_cfg_t *) conn->buf;
- if (rx_cfg->magic == SOCK_TEST_CFG_CTRL_MAGIC)
+ rx_cfg = (vcl_test_cfg_t *) conn->buf;
+ if (rx_cfg->magic == VCL_TEST_CFG_CTRL_MAGIC)
{
if (rx_cfg->verbose)
{
printf ("SERVER (fd %d): Received a cfg message!\n",
client_fd);
- sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
+ vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
}
if (rx_bytes != sizeof (*rx_cfg))
@@ -855,7 +855,7 @@
{
printf ("SERVER (fd %d): Replying to "
"cfg message!\n", client_fd);
- sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
+ vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
}
sock_test_write (client_fd, (uint8_t *) & conn->cfg,
sizeof (conn->cfg), NULL,
@@ -865,17 +865,17 @@
switch (rx_cfg->test)
{
- case SOCK_TEST_TYPE_NONE:
- case SOCK_TEST_TYPE_ECHO:
+ case VCL_TEST_TYPE_NONE:
+ case VCL_TEST_TYPE_ECHO:
sync_config_and_reply (conn, rx_cfg);
break;
- case SOCK_TEST_TYPE_BI:
- case SOCK_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
+ case VCL_TEST_TYPE_UNI:
stream_test_server_start_stop (conn, rx_cfg);
break;
- case SOCK_TEST_TYPE_EXIT:
+ case VCL_TEST_TYPE_EXIT:
printf ("SERVER: Have a great day, "
"connection %d!\n", client_fd);
#ifdef VCL_TEST
@@ -902,14 +902,14 @@
default:
fprintf (stderr,
"SERVER: ERROR: Unknown test type!\n");
- sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
+ vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
break;
}
continue;
}
- else if ((conn->cfg.test == SOCK_TEST_TYPE_UNI) ||
- (conn->cfg.test == SOCK_TEST_TYPE_BI))
+ else if ((conn->cfg.test == VCL_TEST_TYPE_UNI) ||
+ (conn->cfg.test == VCL_TEST_TYPE_BI))
{
stream_test_server (conn, rx_bytes);
if (ioctl (conn->fd, FIONREAD))
diff --git a/src/vcl/vcl_test.h b/src/vcl/vcl_test.h
index 68750af..927110f 100644
--- a/src/vcl/vcl_test.h
+++ b/src/vcl/vcl_test.h
@@ -21,7 +21,6 @@
#include <stdlib.h>
#include <string.h>
#include <vcl/vppcom.h>
-#include <vcl/sock_test_common.h>
#define vtfail(_fn, _rv) \
{ \
@@ -46,35 +45,330 @@
#define vt_atomic_add(_ptr, _val) \
__atomic_fetch_add (_ptr, _val, __ATOMIC_RELEASE)
+#define VCL_TEST_TOKEN_HELP "#H"
+#define VCL_TEST_TOKEN_EXIT "#X"
+#define VCL_TEST_TOKEN_VERBOSE "#V"
+#define VCL_TEST_TOKEN_TXBUF_SIZE "#T:"
+#define VCL_TEST_TOKEN_NUM_TEST_SESS "#I:"
+#define VCL_TEST_TOKEN_NUM_WRITES "#N:"
+#define VCL_TEST_TOKEN_RXBUF_SIZE "#R:"
+#define VCL_TEST_TOKEN_SHOW_CFG "#C"
+#define VCL_TEST_TOKEN_RUN_UNI "#U"
+#define VCL_TEST_TOKEN_RUN_BI "#B"
+
+#define VCL_TEST_SERVER_PORT 22000
+#define VCL_TEST_LOCALHOST_IPADDR "127.0.0.1"
+
+#define VCL_TEST_CFG_CTRL_MAGIC 0xfeedface
+#define VCL_TEST_CFG_NUM_WRITES_DEF 1000000
+#define VCL_TEST_CFG_TXBUF_SIZE_DEF 8192
+#define VCL_TEST_CFG_RXBUF_SIZE_DEF (64*VCL_TEST_CFG_TXBUF_SIZE_DEF)
+#define VCL_TEST_CFG_BUF_SIZE_MIN 128
+#define VCL_TEST_CFG_MAX_TEST_SESS 32
+#define VCL_TEST_CFG_MAX_EPOLL_EVENTS 16
+
+#define VCL_TEST_DELAY_DISCONNECT 1
+#define VCL_TEST_SEPARATOR_STRING \
+ " -----------------------------\n"
+typedef enum
+{
+ VCL_TEST_TYPE_NONE,
+ VCL_TEST_TYPE_ECHO,
+ VCL_TEST_TYPE_UNI,
+ VCL_TEST_TYPE_BI,
+ VCL_TEST_TYPE_EXIT,
+} vcl_test_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint32_t magic;
+ uint32_t seq_num;
+ uint32_t test;
+ uint32_t ctrl_handle;
+ uint32_t num_test_sessions;
+ uint32_t verbose;
+ uint32_t address_ip6;
+ uint32_t transport_udp;
+ uint64_t rxbuf_size;
+ uint64_t txbuf_size;
+ uint64_t num_writes;
+ uint64_t total_bytes;
+} vcl_test_cfg_t;
+
+typedef struct
+{
+ uint64_t rx_xacts;
+ uint64_t rx_bytes;
+ uint32_t rx_eagain;
+ uint32_t rx_incomp;
+ uint64_t tx_xacts;
+ uint64_t tx_bytes;
+ uint32_t tx_eagain;
+ uint32_t tx_incomp;
+ struct timespec start;
+ struct timespec stop;
+} vcl_test_stats_t;
+
+typedef struct
+{
+ int fd;
+ uint32_t txbuf_size;
+ char *txbuf;
+ uint32_t rxbuf_size;
+ char *rxbuf;
+ vcl_test_cfg_t cfg;
+ vcl_test_stats_t stats;
+} vcl_test_session_t;
+
+static inline void
+vcl_test_stats_accumulate (vcl_test_stats_t * accum, vcl_test_stats_t * incr)
+{
+ accum->rx_xacts += incr->rx_xacts;
+ accum->rx_bytes += incr->rx_bytes;
+ accum->rx_eagain += incr->rx_eagain;
+ accum->rx_incomp += incr->rx_incomp;
+ accum->tx_xacts += incr->tx_xacts;
+ accum->tx_bytes += incr->tx_bytes;
+ accum->tx_eagain += incr->tx_eagain;
+ accum->tx_incomp += incr->tx_incomp;
+}
+
+static inline void
+vcl_test_cfg_init (vcl_test_cfg_t * cfg)
+{
+ cfg->magic = VCL_TEST_CFG_CTRL_MAGIC;
+ cfg->test = VCL_TEST_TYPE_NONE;
+ cfg->ctrl_handle = ~0;
+ cfg->num_test_sessions = 1;
+ cfg->verbose = 0;
+ cfg->rxbuf_size = VCL_TEST_CFG_RXBUF_SIZE_DEF;
+ cfg->num_writes = VCL_TEST_CFG_NUM_WRITES_DEF;
+ cfg->txbuf_size = VCL_TEST_CFG_TXBUF_SIZE_DEF;
+ cfg->total_bytes = cfg->num_writes * cfg->txbuf_size;
+}
+
static inline int
-vcl_test_read (int fd, uint8_t *buf, uint32_t nbytes,
- sock_test_stats_t *stats)
+vcl_test_cfg_verify (vcl_test_cfg_t * cfg, vcl_test_cfg_t * valid_cfg)
+{
+ /* Note: txbuf & rxbuf on server are the same buffer,
+ * so txbuf_size is not included in this check.
+ */
+ return ((cfg->magic == valid_cfg->magic)
+ && (cfg->test == valid_cfg->test)
+ && (cfg->verbose == valid_cfg->verbose)
+ && (cfg->rxbuf_size == valid_cfg->rxbuf_size)
+ && (cfg->num_writes == valid_cfg->num_writes)
+ && (cfg->total_bytes == valid_cfg->total_bytes));
+}
+
+static inline void
+vcl_test_buf_alloc (vcl_test_cfg_t * cfg, uint8_t is_rxbuf, uint8_t ** buf,
+ uint32_t * bufsize)
+{
+ uint32_t alloc_size = is_rxbuf ? cfg->rxbuf_size : cfg->txbuf_size;
+ uint8_t *lb = realloc (*buf, (size_t) alloc_size);
+
+ if (lb)
+ {
+ if (is_rxbuf)
+ cfg->rxbuf_size = *bufsize = alloc_size;
+ else
+ cfg->txbuf_size = *bufsize = alloc_size;
+
+ *buf = lb;
+ }
+ else
+ {
+ vtwrn ("realloc failed. using buffer size %d instead of %u",
+ *bufsize, alloc_size);
+ }
+}
+
+static inline void
+vcl_test_session_buf_alloc (vcl_test_session_t * socket)
+{
+ socket->rxbuf_size = socket->cfg.rxbuf_size;
+ socket->txbuf_size = socket->cfg.txbuf_size;
+ vcl_test_buf_alloc (&socket->cfg, 0 /* is_rxbuf */ ,
+ (uint8_t **) & socket->txbuf, &socket->txbuf_size);
+ vcl_test_buf_alloc (&socket->cfg, 1 /* is_rxbuf */ ,
+ (uint8_t **) & socket->rxbuf, &socket->rxbuf_size);
+}
+
+static inline char *
+vcl_test_type_str (vcl_test_t t)
+{
+ switch (t)
+ {
+ case VCL_TEST_TYPE_NONE:
+ return "NONE";
+
+ case VCL_TEST_TYPE_ECHO:
+ return "ECHO";
+
+ case VCL_TEST_TYPE_UNI:
+ return "UNI";
+
+ case VCL_TEST_TYPE_BI:
+ return "BI";
+
+ case VCL_TEST_TYPE_EXIT:
+ return "EXIT";
+
+ default:
+ return "Unknown";
+ }
+}
+
+static inline void
+vcl_test_cfg_dump (vcl_test_cfg_t * cfg, uint8_t is_client)
+{
+ char *spc = " ";
+
+ printf (" test config (%p):\n"
+ VCL_TEST_SEPARATOR_STRING
+ " magic: 0x%08x\n"
+ " seq_num: 0x%08x\n"
+ "%-5s test: %s (%d)\n"
+ " ctrl handle: %d (0x%x)\n"
+ "%-5s num test sockets: %u (0x%08x)\n"
+ "%-5s verbose: %s (%d)\n"
+ "%-5s rxbuf size: %lu (0x%08lx)\n"
+ "%-5s txbuf size: %lu (0x%08lx)\n"
+ "%-5s num writes: %lu (0x%08lx)\n"
+ " client tx bytes: %lu (0x%08lx)\n"
+ VCL_TEST_SEPARATOR_STRING,
+ (void *) cfg, cfg->magic, cfg->seq_num,
+ is_client && (cfg->test == VCL_TEST_TYPE_UNI) ?
+ "'" VCL_TEST_TOKEN_RUN_UNI "'" :
+ is_client && (cfg->test == VCL_TEST_TYPE_BI) ?
+ "'" VCL_TEST_TOKEN_RUN_BI "'" : spc,
+ vcl_test_type_str (cfg->test), cfg->test,
+ cfg->ctrl_handle, cfg->ctrl_handle,
+ is_client ? "'" VCL_TEST_TOKEN_NUM_TEST_SESS "'" : spc,
+ cfg->num_test_sessions, cfg->num_test_sessions,
+ is_client ? "'" VCL_TEST_TOKEN_VERBOSE "'" : spc,
+ cfg->verbose ? "on" : "off", cfg->verbose,
+ is_client ? "'" VCL_TEST_TOKEN_RXBUF_SIZE "'" : spc,
+ cfg->rxbuf_size, cfg->rxbuf_size,
+ is_client ? "'" VCL_TEST_TOKEN_TXBUF_SIZE "'" : spc,
+ cfg->txbuf_size, cfg->txbuf_size,
+ is_client ? "'" VCL_TEST_TOKEN_NUM_WRITES "'" : spc,
+ cfg->num_writes, cfg->num_writes,
+ cfg->total_bytes, cfg->total_bytes);
+}
+
+static inline void
+vcl_test_stats_dump (char *header, vcl_test_stats_t * stats,
+ uint8_t show_rx, uint8_t show_tx, uint8_t verbose)
+{
+ struct timespec diff;
+ double duration, rate;
+ uint64_t total_bytes;
+
+ if ((stats->stop.tv_nsec - stats->start.tv_nsec) < 0)
+ {
+ diff.tv_sec = stats->stop.tv_sec - stats->start.tv_sec - 1;
+ diff.tv_nsec = stats->stop.tv_nsec - stats->start.tv_nsec + 1e9;
+ }
+ else
+ {
+ diff.tv_sec = stats->stop.tv_sec - stats->start.tv_sec;
+ diff.tv_nsec = stats->stop.tv_nsec - stats->start.tv_nsec;
+ }
+ duration = (double) diff.tv_sec + (1e-9 * diff.tv_nsec);
+
+ total_bytes = stats->tx_bytes + stats->rx_bytes;
+ rate = (double) total_bytes *8 / duration / 1e9;
+ printf ("\n%s: Streamed %lu bytes\n"
+ " in %lf seconds (%lf Gbps %s-duplex)!\n",
+ header, total_bytes, duration, rate,
+ (show_rx && show_tx) ? "full" : "half");
+
+ if (show_tx)
+ {
+ printf (VCL_TEST_SEPARATOR_STRING
+ " tx stats (0x%p):\n"
+ VCL_TEST_SEPARATOR_STRING
+ " writes: %lu (0x%08lx)\n"
+ " tx bytes: %lu (0x%08lx)\n"
+ " tx eagain: %u (0x%08x)\n"
+ " tx incomplete: %u (0x%08x)\n",
+ (void *) stats, stats->tx_xacts, stats->tx_xacts,
+ stats->tx_bytes, stats->tx_bytes,
+ stats->tx_eagain, stats->tx_eagain,
+ stats->tx_incomp, stats->tx_incomp);
+ }
+ if (show_rx)
+ {
+ printf (VCL_TEST_SEPARATOR_STRING
+ " rx stats (0x%p):\n"
+ VCL_TEST_SEPARATOR_STRING
+ " reads: %lu (0x%08lx)\n"
+ " rx bytes: %lu (0x%08lx)\n"
+ " rx eagain: %u (0x%08x)\n"
+ " rx incomplete: %u (0x%08x)\n",
+ (void *) stats, stats->rx_xacts, stats->rx_xacts,
+ stats->rx_bytes, stats->rx_bytes,
+ stats->rx_eagain, stats->rx_eagain,
+ stats->rx_incomp, stats->rx_incomp);
+ }
+ if (verbose)
+ printf (" start.tv_sec: %ld\n"
+ " start.tv_nsec: %ld\n"
+ " stop.tv_sec: %ld\n"
+ " stop.tv_nsec: %ld\n",
+ stats->start.tv_sec, stats->start.tv_nsec,
+ stats->stop.tv_sec, stats->stop.tv_nsec);
+
+ printf (VCL_TEST_SEPARATOR_STRING);
+}
+
+static inline int
+vcl_comp_tspec (struct timespec *a, struct timespec *b)
+{
+ if (a->tv_sec < b->tv_sec)
+ return -1;
+ else if (a->tv_sec > b->tv_sec)
+ return 1;
+ else if (a->tv_nsec < b->tv_nsec)
+ return -1;
+ else if (a->tv_nsec > b->tv_nsec)
+ return 1;
+ else
+ return 0;
+}
+
+static inline int
+vcl_test_read (int fd, uint8_t * buf, uint32_t nbytes,
+ vcl_test_stats_t * stats)
{
int rx_bytes, errno_val;
-
+
do
{
if (stats)
- stats->rx_xacts++;
+ stats->rx_xacts++;
rx_bytes = vppcom_session_read (fd, buf, nbytes);
if (rx_bytes < 0)
- {
- errno = -rx_bytes;
- rx_bytes = -1;
- }
+ {
+ errno = -rx_bytes;
+ rx_bytes = -1;
+ }
if (stats)
- {
- if ((rx_bytes == 0) ||
- ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
- stats->rx_eagain++;
- else if (rx_bytes < nbytes)
- stats->rx_incomp++;
- }
+ {
+ if ((rx_bytes == 0) ||
+ ((rx_bytes < 0)
+ && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
+ stats->rx_eagain++;
+ else if (rx_bytes < nbytes)
+ stats->rx_incomp++;
+ }
}
while ((rx_bytes == 0) ||
- ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
-
+ ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
+
if (rx_bytes < 0)
{
vterr ("vppcom_session_read()", -errno);
@@ -86,30 +380,31 @@
}
static inline int
-vcl_test_read_ds (int fd, vppcom_data_segments_t ds, sock_test_stats_t *stats)
+vcl_test_read_ds (int fd, vppcom_data_segments_t ds, vcl_test_stats_t * stats)
{
int rx_bytes, errno_val;
do
{
if (stats)
- stats->rx_xacts++;
+ stats->rx_xacts++;
rx_bytes = vppcom_session_read_segments (fd, ds);
if (rx_bytes < 0)
- {
- errno = -rx_bytes;
- rx_bytes = -1;
- }
+ {
+ errno = -rx_bytes;
+ rx_bytes = -1;
+ }
if (stats)
- {
- if ((rx_bytes == 0) ||
- ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
- stats->rx_eagain++;
- }
+ {
+ if ((rx_bytes == 0) ||
+ ((rx_bytes < 0)
+ && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
+ stats->rx_eagain++;
+ }
}
while ((rx_bytes == 0) ||
- ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
+ ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
if (rx_bytes < 0)
{
@@ -122,42 +417,43 @@
}
static inline int
-vcl_test_write (int fd, uint8_t *buf, uint32_t nbytes,
- sock_test_stats_t *stats, uint32_t verbose)
+vcl_test_write (int fd, uint8_t * buf, uint32_t nbytes,
+ vcl_test_stats_t * stats, uint32_t verbose)
{
int tx_bytes = 0, nbytes_left = nbytes, rv;
do
{
if (stats)
- stats->tx_xacts++;
+ stats->tx_xacts++;
rv = vppcom_session_write (fd, buf, nbytes_left);
if (rv < 0)
- {
- errno = -rv;
- rv = -1;
- }
+ {
+ errno = -rv;
+ rv = -1;
+ }
if (rv < 0)
- {
- if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
- {
- if (stats)
- stats->tx_eagain++;
- continue;
- }
- else
- break;
- }
+ {
+ if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
+ {
+ if (stats)
+ stats->tx_eagain++;
+ continue;
+ }
+ else
+ break;
+ }
tx_bytes += rv;
-
+
if (tx_bytes != nbytes)
- {
- nbytes_left = nbytes_left - rv;
- if (stats)
- stats->tx_incomp++;
- }
-
- } while (tx_bytes != nbytes);
+ {
+ nbytes_left = nbytes_left - rv;
+ if (stats)
+ stats->tx_incomp++;
+ }
+
+ }
+ while (tx_bytes != nbytes);
if (tx_bytes < 0)
{
@@ -165,8 +461,16 @@
}
else if (stats)
stats->tx_bytes += tx_bytes;
-
+
return (tx_bytes);
}
#endif /* __vcl_test_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vcl/vcl_test_client.c b/src/vcl/vcl_test_client.c
index cd92ed8..59286ee 100644
--- a/src/vcl/vcl_test_client.c
+++ b/src/vcl/vcl_test_client.c
@@ -27,14 +27,14 @@
typedef struct
{
- sock_test_socket_t *sessions;
+ vcl_test_session_t *sessions;
uint32_t n_sessions;
uint32_t wrk_index;
fd_set wr_fdset;
fd_set rd_fdset;
int max_fd_index;
pthread_t thread_handle;
- sock_test_cfg_t cfg;
+ vcl_test_cfg_t cfg;
} vcl_test_client_worker_t;
typedef struct
@@ -42,10 +42,10 @@
vcl_test_client_worker_t *workers;
vppcom_endpt_t server_endpt;
uint32_t cfg_seq_num;
- sock_test_socket_t ctrl_socket;
- sock_test_socket_t *sessions;
+ vcl_test_session_t ctrl_session;
+ vcl_test_session_t *sessions;
uint8_t dump_cfg;
- sock_test_t post_test;
+ vcl_test_t post_test;
uint32_t proto;
uint32_t n_workers;
volatile int active_workers;
@@ -60,57 +60,57 @@
#define vtc_max(a, b) (a > b ? a : b)
static int
-vtc_cfg_sync (sock_test_socket_t * sock)
+vtc_cfg_sync (vcl_test_session_t * ts)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_cfg_t *rx_cfg = (sock_test_cfg_t *) sock->rxbuf;
+ vcl_test_cfg_t *rx_cfg = (vcl_test_cfg_t *) ts->rxbuf;
int rx_bytes, tx_bytes;
- vt_atomic_add (&sock->cfg.seq_num, 1);
- if (sock->cfg.verbose)
+ vt_atomic_add (&ts->cfg.seq_num, 1);
+ if (ts->cfg.verbose)
{
- vtinf ("(fd %d): Sending config to server.", sock->fd);
- sock_test_cfg_dump (&sock->cfg, 1 /* is_client */ );
+ vtinf ("(fd %d): Sending config to server.", ts->fd);
+ vcl_test_cfg_dump (&ts->cfg, 1 /* is_client */ );
}
- tx_bytes = vcl_test_write (sock->fd, (uint8_t *) & sock->cfg,
- sizeof (sock->cfg), NULL, sock->cfg.verbose);
+ tx_bytes = vcl_test_write (ts->fd, (uint8_t *) & ts->cfg,
+ sizeof (ts->cfg), NULL, ts->cfg.verbose);
if (tx_bytes < 0)
{
- vtwrn ("(fd %d): write test cfg failed (%d)!", sock->fd, tx_bytes);
+ vtwrn ("(fd %d): write test cfg failed (%d)!", ts->fd, tx_bytes);
return tx_bytes;
}
- rx_bytes = vcl_test_read (sock->fd, (uint8_t *) sock->rxbuf,
- sizeof (sock_test_cfg_t), NULL);
+ rx_bytes = vcl_test_read (ts->fd, (uint8_t *) ts->rxbuf,
+ sizeof (vcl_test_cfg_t), NULL);
if (rx_bytes < 0)
return rx_bytes;
- if (rx_cfg->magic != SOCK_TEST_CFG_CTRL_MAGIC)
+ if (rx_cfg->magic != VCL_TEST_CFG_CTRL_MAGIC)
{
- vtwrn ("(fd %d): Bad server reply cfg -- aborting!", sock->fd);
+ vtwrn ("(fd %d): Bad server reply cfg -- aborting!", ts->fd);
return -1;
}
- if ((rx_bytes != sizeof (sock_test_cfg_t))
- || !sock_test_cfg_verify (rx_cfg, &sock->cfg))
+ if ((rx_bytes != sizeof (vcl_test_cfg_t))
+ || !vcl_test_cfg_verify (rx_cfg, &ts->cfg))
{
- vtwrn ("(fd %d): Invalid config received from server!", sock->fd);
- if (rx_bytes != sizeof (sock_test_cfg_t))
+ vtwrn ("(fd %d): Invalid config received from server!", ts->fd);
+ if (rx_bytes != sizeof (vcl_test_cfg_t))
{
vtinf ("\tRx bytes %d != cfg size %lu", rx_bytes,
- sizeof (sock_test_cfg_t));
+ sizeof (vcl_test_cfg_t));
}
else
{
- sock_test_cfg_dump (rx_cfg, 1 /* is_client */ );
- vtinf ("(fd %d): Valid config sent to server.", sock->fd);
- sock_test_cfg_dump (&sock->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (rx_cfg, 1 /* is_client */ );
+ vtinf ("(fd %d): Valid config sent to server.", ts->fd);
+ vcl_test_cfg_dump (&ts->cfg, 1 /* is_client */ );
}
return -1;
}
- if (sock->cfg.verbose)
+ if (ts->cfg.verbose)
{
- vtinf ("(fd %d): Got config back from server.", sock->fd);
- sock_test_cfg_dump (rx_cfg, 1 /* is_client */ );
+ vtinf ("(fd %d): Got config back from server.", ts->fd);
+ vcl_test_cfg_dump (rx_cfg, 1 /* is_client */ );
}
return 0;
@@ -120,11 +120,11 @@
vtc_connect_test_sessions (vcl_test_client_worker_t * wrk)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ts;
uint32_t n_test_sessions;
int i, rv;
- n_test_sessions = wrk->cfg.num_test_sockets;
+ n_test_sessions = wrk->cfg.num_test_sessions;
if (n_test_sessions < 1)
{
errno = EINVAL;
@@ -136,9 +136,9 @@
if (wrk->n_sessions)
wrk->sessions = realloc (wrk->sessions,
- n_test_sessions * sizeof (sock_test_socket_t));
+ n_test_sessions * sizeof (vcl_test_session_t));
else
- wrk->sessions = calloc (n_test_sessions, sizeof (sock_test_socket_t));
+ wrk->sessions = calloc (n_test_sessions, sizeof (vcl_test_session_t));
if (!wrk->sessions)
{
@@ -148,21 +148,21 @@
for (i = 0; i < n_test_sessions; i++)
{
- tsock = &wrk->sessions[i];
- tsock->fd = vppcom_session_create (vcm->proto, 1 /* is_nonblocking */ );
- if (tsock->fd < 0)
+ ts = &wrk->sessions[i];
+ ts->fd = vppcom_session_create (vcm->proto, 1 /* is_nonblocking */ );
+ if (ts->fd < 0)
{
- vterr ("vppcom_session_create()", tsock->fd);
- return tsock->fd;
+ vterr ("vppcom_session_create()", ts->fd);
+ return ts->fd;
}
- rv = vppcom_session_connect (tsock->fd, &vcm->server_endpt);
+ rv = vppcom_session_connect (ts->fd, &vcm->server_endpt);
if (rv < 0)
{
vterr ("vppcom_session_connect()", rv);
return rv;
}
- vtinf ("(fd %d): Test socket %d connected.", tsock->fd, i);
+ vtinf ("Test session %d (fd %d) connected.", i, ts->fd);
}
wrk->n_sessions = n_test_sessions;
@@ -175,36 +175,36 @@
vtc_worker_test_setup (vcl_test_client_worker_t * wrk)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- sock_test_cfg_t *cfg = &wrk->cfg;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ vcl_test_cfg_t *cfg = &wrk->cfg;
+ vcl_test_session_t *ts;
uint32_t sidx;
int i, j;
FD_ZERO (&wrk->wr_fdset);
FD_ZERO (&wrk->rd_fdset);
- for (i = 0; i < cfg->num_test_sockets; i++)
+ for (i = 0; i < cfg->num_test_sessions; i++)
{
- tsock = &wrk->sessions[i];
- tsock->cfg = wrk->cfg;
- sock_test_socket_buf_alloc (tsock);
+ ts = &wrk->sessions[i];
+ ts->cfg = wrk->cfg;
+ vcl_test_session_buf_alloc (ts);
switch (cfg->test)
{
- case SOCK_TEST_TYPE_ECHO:
- memcpy (tsock->txbuf, ctrl->txbuf, cfg->total_bytes);
+ case VCL_TEST_TYPE_ECHO:
+ memcpy (ts->txbuf, ctrl->txbuf, cfg->total_bytes);
break;
- case SOCK_TEST_TYPE_UNI:
- case SOCK_TEST_TYPE_BI:
- for (j = 0; j < tsock->txbuf_size; j++)
- tsock->txbuf[j] = j & 0xff;
+ case VCL_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
+ for (j = 0; j < ts->txbuf_size; j++)
+ ts->txbuf[j] = j & 0xff;
break;
}
- FD_SET (vppcom_session_index (tsock->fd), &wrk->wr_fdset);
- FD_SET (vppcom_session_index (tsock->fd), &wrk->rd_fdset);
- sidx = vppcom_session_index (tsock->fd);
+ FD_SET (vppcom_session_index (ts->fd), &wrk->wr_fdset);
+ FD_SET (vppcom_session_index (ts->fd), &wrk->rd_fdset);
+ sidx = vppcom_session_index (ts->fd);
wrk->max_fd_index = vtc_max (sidx, wrk->max_fd_index);
}
wrk->max_fd_index += 1;
@@ -216,15 +216,15 @@
vtc_worker_init (vcl_test_client_worker_t * wrk)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- sock_test_cfg_t *cfg = &wrk->cfg;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ vcl_test_cfg_t *cfg = &wrk->cfg;
+ vcl_test_session_t *ts;
uint32_t i, n;
int rv, nbytes;
__wrk_index = wrk->wrk_index;
- vtinf ("Initializing worker ...");
+ vtinf ("Initializing worker %u ...", wrk->wrk_index);
if (wrk->wrk_index)
{
@@ -238,7 +238,7 @@
rv = vtc_connect_test_sessions (wrk);
if (rv)
{
- vterr ("vtc_connect_test_sockets ()", rv);
+ vterr ("vtc_connect_test_sessions ()", rv);
return rv;
}
@@ -247,12 +247,12 @@
vtinf ("Sending config to server on all sessions ...");
- for (n = 0; n < cfg->num_test_sockets; n++)
+ for (n = 0; n < cfg->num_test_sessions; n++)
{
- tsock = &wrk->sessions[n];
- if (vtc_cfg_sync (tsock))
+ ts = &wrk->sessions[n];
+ if (vtc_cfg_sync (ts))
return -1;
- memset (&tsock->stats, 0, sizeof (tsock->stats));
+ memset (&ts->stats, 0, sizeof (ts->stats));
}
return 0;
@@ -262,32 +262,34 @@
static void
vtc_accumulate_stats (vcl_test_client_worker_t * wrk,
- sock_test_socket_t * ctrl)
+ vcl_test_session_t * ctrl)
{
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ts;
static char buf[64];
int i, show_rx = 0;
while (__sync_lock_test_and_set (&stats_lock, 1))
;
- if (ctrl->cfg.test == SOCK_TEST_TYPE_BI
- || ctrl->cfg.test == SOCK_TEST_TYPE_ECHO)
+ if (ctrl->cfg.test == VCL_TEST_TYPE_BI
+ || ctrl->cfg.test == VCL_TEST_TYPE_ECHO)
show_rx = 1;
- for (i = 0; i < wrk->cfg.num_test_sockets; i++)
+ for (i = 0; i < wrk->cfg.num_test_sessions; i++)
{
- tsock = &wrk->sessions[i];
- tsock->stats.start = ctrl->stats.start;
+ ts = &wrk->sessions[i];
+ ts->stats.start = ctrl->stats.start;
if (ctrl->cfg.verbose > 1)
{
- sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
- sock_test_stats_dump (buf, &tsock->stats, show_rx, 1 /* show tx */ ,
- ctrl->cfg.verbose);
+ sprintf (buf, "CLIENT (fd %d) RESULTS", ts->fd);
+ vcl_test_stats_dump (buf, &ts->stats, show_rx, 1 /* show tx */ ,
+ ctrl->cfg.verbose);
}
- sock_test_stats_accumulate (&ctrl->stats, &tsock->stats);
+ vcl_test_stats_accumulate (&ctrl->stats, &ts->stats);
+ if (vcl_comp_tspec (&ctrl->stats.stop, &ts->stats.stop) < 0)
+ ctrl->stats.stop = ts->stats.stop;
}
__sync_lock_release (&stats_lock);
@@ -297,22 +299,22 @@
vtc_worker_sessions_exit (vcl_test_client_worker_t * wrk)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ vcl_test_session_t *ts;
int i, verbose = ctrl->cfg.verbose;
- for (i = 0; i < wrk->cfg.num_test_sockets; i++)
+ for (i = 0; i < wrk->cfg.num_test_sessions; i++)
{
- tsock = &wrk->sessions[i];
- tsock->cfg.test = SOCK_TEST_TYPE_EXIT;
+ ts = &wrk->sessions[i];
+ ts->cfg.test = VCL_TEST_TYPE_EXIT;
if (verbose)
{
- vtinf ("(fd %d): Sending exit cfg to server...", tsock->fd);
- sock_test_cfg_dump (&tsock->cfg, 1 /* is_client */ );
+ vtinf ("(fd %d): Sending exit cfg to server...", ts->fd);
+ vcl_test_cfg_dump (&ts->cfg, 1 /* is_client */ );
}
- (void) vcl_test_write (tsock->fd, (uint8_t *) & tsock->cfg,
- sizeof (tsock->cfg), &tsock->stats, verbose);
+ (void) vcl_test_write (ts->fd, (uint8_t *) & ts->cfg,
+ sizeof (ts->cfg), &ts->stats, verbose);
}
wrk->n_sessions = 0;
}
@@ -321,12 +323,12 @@
vtc_worker_loop (void *arg)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
vcl_test_client_worker_t *wrk = arg;
uint32_t n_active_sessions, n_bytes;
fd_set _wfdset, *wfdset = &_wfdset;
fd_set _rfdset, *rfdset = &_rfdset;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ts;
int i, rv, check_rx = 0;
rv = vtc_worker_init (wrk);
@@ -341,8 +343,8 @@
if (wrk->wrk_index == 0)
clock_gettime (CLOCK_REALTIME, &ctrl->stats.start);
- check_rx = wrk->cfg.test != SOCK_TEST_TYPE_UNI;
- n_active_sessions = wrk->cfg.num_test_sockets;
+ check_rx = wrk->cfg.test != VCL_TEST_TYPE_UNI;
+ n_active_sessions = wrk->cfg.num_test_sessions;
while (n_active_sessions)
{
_wfdset = wrk->wr_fdset;
@@ -358,51 +360,49 @@
else if (rv == 0)
continue;
- for (i = 0; i < wrk->cfg.num_test_sockets; i++)
+ for (i = 0; i < wrk->cfg.num_test_sessions; i++)
{
- tsock = &wrk->sessions[i];
- if (!((tsock->stats.stop.tv_sec == 0) &&
- (tsock->stats.stop.tv_nsec == 0)))
+ ts = &wrk->sessions[i];
+ if (!((ts->stats.stop.tv_sec == 0) &&
+ (ts->stats.stop.tv_nsec == 0)))
continue;
- if (FD_ISSET (vppcom_session_index (tsock->fd), rfdset)
- && tsock->stats.rx_bytes < tsock->cfg.total_bytes)
+ if (FD_ISSET (vppcom_session_index (ts->fd), rfdset)
+ && ts->stats.rx_bytes < ts->cfg.total_bytes)
{
- (void) vcl_test_read (tsock->fd, (uint8_t *) tsock->rxbuf,
- tsock->rxbuf_size, &tsock->stats);
+ (void) vcl_test_read (ts->fd, (uint8_t *) ts->rxbuf,
+ ts->rxbuf_size, &ts->stats);
}
- if (FD_ISSET (vppcom_session_index (tsock->fd), wfdset)
- && tsock->stats.tx_bytes < tsock->cfg.total_bytes)
+ if (FD_ISSET (vppcom_session_index (ts->fd), wfdset)
+ && ts->stats.tx_bytes < ts->cfg.total_bytes)
{
- n_bytes = tsock->cfg.txbuf_size;
- if (tsock->cfg.test == SOCK_TEST_TYPE_ECHO)
+ n_bytes = ts->cfg.txbuf_size;
+ if (ts->cfg.test == VCL_TEST_TYPE_ECHO)
n_bytes = strlen (ctrl->txbuf) + 1;
- rv = vcl_test_write (tsock->fd, (uint8_t *) tsock->txbuf,
- n_bytes, &tsock->stats,
- tsock->cfg.verbose);
+ rv = vcl_test_write (ts->fd, (uint8_t *) ts->txbuf,
+ n_bytes, &ts->stats, ts->cfg.verbose);
if (rv < 0)
{
vtwrn ("vppcom_test_write (%d) failed -- aborting test",
- tsock->fd);
+ ts->fd);
goto exit;
}
}
- if ((!check_rx && tsock->stats.tx_bytes >= tsock->cfg.total_bytes)
- || (check_rx
- && tsock->stats.rx_bytes >= tsock->cfg.total_bytes))
+ if ((!check_rx && ts->stats.tx_bytes >= ts->cfg.total_bytes)
+ || (check_rx && ts->stats.rx_bytes >= ts->cfg.total_bytes))
{
- clock_gettime (CLOCK_REALTIME, &tsock->stats.stop);
+ clock_gettime (CLOCK_REALTIME, &ts->stats.stop);
n_active_sessions--;
}
}
}
exit:
vtinf ("Worker %d done ...", wrk->wrk_index);
- if (wrk->cfg.test != SOCK_TEST_TYPE_ECHO)
+ if (wrk->cfg.test != VCL_TEST_TYPE_ECHO)
vtc_accumulate_stats (wrk, ctrl);
- sleep (1);
+ sleep (VCL_TEST_DELAY_DISCONNECT);
vtc_worker_sessions_exit (wrk);
if (wrk->wrk_index)
vt_atomic_add (&vcm->active_workers, -1);
@@ -410,31 +410,31 @@
}
static void
-vtc_print_stats (sock_test_socket_t * ctrl)
+vtc_print_stats (vcl_test_session_t * ctrl)
{
- int is_echo = ctrl->cfg.test == SOCK_TEST_TYPE_ECHO;
+ int is_echo = ctrl->cfg.test == VCL_TEST_TYPE_ECHO;
int show_rx = 0;
char buf[64];
- if (ctrl->cfg.test == SOCK_TEST_TYPE_BI
- || ctrl->cfg.test == SOCK_TEST_TYPE_ECHO)
+ if (ctrl->cfg.test == VCL_TEST_TYPE_BI
+ || ctrl->cfg.test == VCL_TEST_TYPE_ECHO)
show_rx = 1;
- sock_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
- show_rx, 1 /* show tx */ ,
- ctrl->cfg.verbose);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_stats_dump ("CLIENT RESULTS", &ctrl->stats,
+ show_rx, 1 /* show tx */ ,
+ ctrl->cfg.verbose);
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
if (ctrl->cfg.verbose)
{
- vtinf (" ctrl socket info\n"
- SOCK_TEST_SEPARATOR_STRING
+ vtinf (" ctrl session info\n"
+ VCL_TEST_SEPARATOR_STRING
" fd: %d (0x%08x)\n"
" rxbuf: %p\n"
" rxbuf size: %u (0x%08x)\n"
" txbuf: %p\n"
" txbuf size: %u (0x%08x)\n"
- SOCK_TEST_SEPARATOR_STRING,
+ VCL_TEST_SEPARATOR_STRING,
ctrl->fd, (uint32_t) ctrl->fd,
ctrl->rxbuf, ctrl->rxbuf_size, ctrl->rxbuf_size,
ctrl->txbuf, ctrl->txbuf_size, ctrl->txbuf_size);
@@ -444,18 +444,15 @@
sprintf (buf, "Echo");
else
sprintf (buf, "%s-directional Stream",
- ctrl->cfg.test == SOCK_TEST_TYPE_BI ? "Bi" : "Uni");
-
- vtinf ("(fd %d): %s Test Complete!\n"
- SOCK_TEST_BANNER_STRING, ctrl->fd, buf);
+ ctrl->cfg.test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
}
static void
vtc_echo_client (vcl_test_client_main_t * vcm)
{
vcl_test_client_worker_t *wrk;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- sock_test_cfg_t *cfg = &ctrl->cfg;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ vcl_test_cfg_t *cfg = &ctrl->cfg;
cfg->total_bytes = strlen (ctrl->txbuf) + 1;
memset (&ctrl->stats, 0, sizeof (ctrl->stats));
@@ -477,15 +474,15 @@
static void
vtc_stream_client (vcl_test_client_main_t * vcm)
{
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- sock_test_cfg_t *cfg = &ctrl->cfg;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ vcl_test_cfg_t *cfg = &ctrl->cfg;
vcl_test_client_worker_t *wrk;
- sock_test_socket_t *tsock;
+ vcl_test_session_t *ts;
int tx_bytes, rv;
uint32_t i, n, sidx, n_conn, n_conn_per_wrk;
- vtinf (SOCK_TEST_BANNER_STRING "%s-directional Stream Test!\n",
- ctrl->cfg.test == SOCK_TEST_TYPE_BI ? "Bi" : "Uni");
+ vtinf ("%s-directional Stream Test Starting!",
+ ctrl->cfg.test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
cfg->total_bytes = cfg->num_writes * cfg->txbuf_size;
cfg->ctrl_handle = ~0;
@@ -494,18 +491,18 @@
vtwrn ("test cfg sync failed -- aborting!");
return;
}
- cfg->ctrl_handle = ((sock_test_cfg_t *) ctrl->rxbuf)->ctrl_handle;
+ cfg->ctrl_handle = ((vcl_test_cfg_t *) ctrl->rxbuf)->ctrl_handle;
memset (&ctrl->stats, 0, sizeof (ctrl->stats));
- n_conn = cfg->num_test_sockets;
+ n_conn = cfg->num_test_sessions;
n_conn_per_wrk = n_conn / vcm->n_workers;
for (i = 0; i < vcm->n_workers; i++)
{
wrk = &vcm->workers[i];
wrk->wrk_index = i;
wrk->cfg = ctrl->cfg;
- wrk->cfg.num_test_sockets = vtc_min (n_conn_per_wrk, n_conn);
- n_conn -= wrk->cfg.num_test_sockets;
+ wrk->cfg.num_test_sessions = vtc_min (n_conn_per_wrk, n_conn);
+ n_conn -= wrk->cfg.num_test_sessions;
}
for (i = 1; i < vcm->n_workers; i++)
@@ -519,9 +516,7 @@
while (vcm->active_workers > 0)
;
- clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop);
-
- vtinf ("(fd %d): Sending config on ctrl socket for stats...\n", ctrl->fd);
+ vtinf ("Sending config on ctrl session (fd %d) for stats...", ctrl->fd);
if (vtc_cfg_sync (ctrl))
{
vtwrn ("test cfg sync failed -- aborting!");
@@ -530,7 +525,7 @@
vtc_print_stats (ctrl);
- ctrl->cfg.test = SOCK_TEST_TYPE_ECHO;
+ ctrl->cfg.test = VCL_TEST_TYPE_ECHO;
ctrl->cfg.total_bytes = 0;
if (vtc_cfg_sync (ctrl))
vtwrn ("post-test cfg sync failed!");
@@ -542,23 +537,23 @@
#define INDENT "\n "
printf ("CLIENT: Test configuration commands:"
- INDENT SOCK_TEST_TOKEN_HELP
+ INDENT VCL_TEST_TOKEN_HELP
"\t\t\tDisplay help."
- INDENT SOCK_TEST_TOKEN_EXIT
+ INDENT VCL_TEST_TOKEN_EXIT
"\t\t\tExit test client & server."
- INDENT SOCK_TEST_TOKEN_SHOW_CFG
+ INDENT VCL_TEST_TOKEN_SHOW_CFG
"\t\t\tShow the current test cfg."
- INDENT SOCK_TEST_TOKEN_RUN_UNI
+ INDENT VCL_TEST_TOKEN_RUN_UNI
"\t\t\tRun the Uni-directional test."
- INDENT SOCK_TEST_TOKEN_RUN_BI
+ INDENT VCL_TEST_TOKEN_RUN_BI
"\t\t\tRun the Bi-directional test."
- INDENT SOCK_TEST_TOKEN_VERBOSE
+ INDENT VCL_TEST_TOKEN_VERBOSE
"\t\t\tToggle verbose setting."
- INDENT SOCK_TEST_TOKEN_RXBUF_SIZE
+ INDENT VCL_TEST_TOKEN_RXBUF_SIZE
"<rxbuf size>\tRx buffer size (bytes)."
- INDENT SOCK_TEST_TOKEN_TXBUF_SIZE
+ INDENT VCL_TEST_TOKEN_TXBUF_SIZE
"<txbuf size>\tTx buffer size (bytes)."
- INDENT SOCK_TEST_TOKEN_NUM_WRITES
+ INDENT VCL_TEST_TOKEN_NUM_WRITES
"<# of writes>\tNumber of txbuf writes to server." "\n");
}
@@ -566,62 +561,61 @@
cfg_txbuf_size_set (void)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- char *p = ctrl->txbuf + strlen (SOCK_TEST_TOKEN_TXBUF_SIZE);
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_TXBUF_SIZE);
uint64_t txbuf_size = strtoull ((const char *) p, NULL, 10);
- if (txbuf_size >= SOCK_TEST_CFG_BUF_SIZE_MIN)
+ if (txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
{
ctrl->cfg.txbuf_size = txbuf_size;
ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
- sock_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
- (uint8_t **) & ctrl->txbuf, &ctrl->txbuf_size);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
+ (uint8_t **) & ctrl->txbuf, &ctrl->txbuf_size);
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
else
- fprintf (stderr, "CLIENT: ERROR: Invalid txbuf size (%lu) < "
- "minimum buf size (%u)!\n",
- txbuf_size, SOCK_TEST_CFG_BUF_SIZE_MIN);
+ vtwrn ("Invalid txbuf size (%lu) < minimum buf size (%u)!",
+ txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
}
static void
cfg_num_writes_set (void)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- char *p = ctrl->txbuf + strlen (SOCK_TEST_TOKEN_NUM_WRITES);
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_WRITES);
uint32_t num_writes = strtoul ((const char *) p, NULL, 10);
if (num_writes > 0)
{
ctrl->cfg.num_writes = num_writes;
ctrl->cfg.total_bytes = ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
else
{
- fprintf (stderr, "CLIENT: ERROR: invalid num writes: %u\n", num_writes);
+ vtwrn ("invalid num writes: %u", num_writes);
}
}
static void
-cfg_num_test_sockets_set (void)
+cfg_num_test_sessions_set (void)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- char *p = ctrl->txbuf + strlen (SOCK_TEST_TOKEN_NUM_TEST_SCKTS);
- uint32_t num_test_sockets = strtoul ((const char *) p, NULL, 10);
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_NUM_TEST_SESS);
+ uint32_t num_test_sessions = strtoul ((const char *) p, NULL, 10);
- if ((num_test_sockets > 0) &&
- (num_test_sockets <= SOCK_TEST_CFG_MAX_TEST_SCKTS))
+ if ((num_test_sessions > 0) &&
+ (num_test_sessions <= VCL_TEST_CFG_MAX_TEST_SESS))
{
- ctrl->cfg.num_test_sockets = num_test_sockets;
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ ctrl->cfg.num_test_sessions = num_test_sessions;
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
else
{
- vtwrn ("invalid num test sockets: %u, (%d max)",
- num_test_sockets, SOCK_TEST_CFG_MAX_TEST_SCKTS);
+ vtwrn ("invalid num test sessions: %u, (%d max)",
+ num_test_sessions, VCL_TEST_CFG_MAX_TEST_SESS);
}
}
@@ -629,83 +623,82 @@
cfg_rxbuf_size_set (void)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- char *p = ctrl->txbuf + strlen (SOCK_TEST_TOKEN_RXBUF_SIZE);
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ char *p = ctrl->txbuf + strlen (VCL_TEST_TOKEN_RXBUF_SIZE);
uint64_t rxbuf_size = strtoull ((const char *) p, NULL, 10);
- if (rxbuf_size >= SOCK_TEST_CFG_BUF_SIZE_MIN)
+ if (rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
{
ctrl->cfg.rxbuf_size = rxbuf_size;
- sock_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
- (uint8_t **) & ctrl->rxbuf, &ctrl->rxbuf_size);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
+ (uint8_t **) & ctrl->rxbuf, &ctrl->rxbuf_size);
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
else
- fprintf (stderr, "CLIENT: ERROR: Invalid rxbuf size (%lu) < "
- "minimum buf size (%u)!\n",
- rxbuf_size, SOCK_TEST_CFG_BUF_SIZE_MIN);
+ vtwrn ("Invalid rxbuf size (%lu) < minimum buf size (%u)!",
+ rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
}
static void
cfg_verbose_toggle (void)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
ctrl->cfg.verbose = ctrl->cfg.verbose ? 0 : 1;
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
-static sock_test_t
+static vcl_test_t
parse_input ()
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
- sock_test_t rv = SOCK_TEST_TYPE_NONE;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+ vcl_test_t rv = VCL_TEST_TYPE_NONE;
- if (!strncmp (SOCK_TEST_TOKEN_EXIT, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_EXIT)))
- rv = SOCK_TEST_TYPE_EXIT;
+ if (!strncmp (VCL_TEST_TOKEN_EXIT, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_EXIT)))
+ rv = VCL_TEST_TYPE_EXIT;
- else if (!strncmp (SOCK_TEST_TOKEN_HELP, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_HELP)))
+ else if (!strncmp (VCL_TEST_TOKEN_HELP, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_HELP)))
dump_help ();
- else if (!strncmp (SOCK_TEST_TOKEN_SHOW_CFG, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_SHOW_CFG)))
+ else if (!strncmp (VCL_TEST_TOKEN_SHOW_CFG, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_SHOW_CFG)))
vcm->dump_cfg = 1;
- else if (!strncmp (SOCK_TEST_TOKEN_VERBOSE, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_VERBOSE)))
+ else if (!strncmp (VCL_TEST_TOKEN_VERBOSE, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_VERBOSE)))
cfg_verbose_toggle ();
- else if (!strncmp (SOCK_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_TXBUF_SIZE)))
+ else if (!strncmp (VCL_TEST_TOKEN_TXBUF_SIZE, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_TXBUF_SIZE)))
cfg_txbuf_size_set ();
- else if (!strncmp (SOCK_TEST_TOKEN_NUM_TEST_SCKTS, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_NUM_TEST_SCKTS)))
- cfg_num_test_sockets_set ();
+ else if (!strncmp (VCL_TEST_TOKEN_NUM_TEST_SESS, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_NUM_TEST_SESS)))
+ cfg_num_test_sessions_set ();
- else if (!strncmp (SOCK_TEST_TOKEN_NUM_WRITES, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_NUM_WRITES)))
+ else if (!strncmp (VCL_TEST_TOKEN_NUM_WRITES, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_NUM_WRITES)))
cfg_num_writes_set ();
- else if (!strncmp (SOCK_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_RXBUF_SIZE)))
+ else if (!strncmp (VCL_TEST_TOKEN_RXBUF_SIZE, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_RXBUF_SIZE)))
cfg_rxbuf_size_set ();
- else if (!strncmp (SOCK_TEST_TOKEN_RUN_UNI, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_RUN_UNI)))
- rv = ctrl->cfg.test = SOCK_TEST_TYPE_UNI;
+ else if (!strncmp (VCL_TEST_TOKEN_RUN_UNI, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_RUN_UNI)))
+ rv = ctrl->cfg.test = VCL_TEST_TYPE_UNI;
- else if (!strncmp (SOCK_TEST_TOKEN_RUN_BI, ctrl->txbuf,
- strlen (SOCK_TEST_TOKEN_RUN_BI)))
- rv = ctrl->cfg.test = SOCK_TEST_TYPE_BI;
+ else if (!strncmp (VCL_TEST_TOKEN_RUN_BI, ctrl->txbuf,
+ strlen (VCL_TEST_TOKEN_RUN_BI)))
+ rv = ctrl->cfg.test = VCL_TEST_TYPE_BI;
else
- rv = SOCK_TEST_TYPE_ECHO;
+ rv = VCL_TEST_TYPE_ECHO;
return rv;
}
@@ -714,7 +707,7 @@
print_usage_and_exit (void)
{
fprintf (stderr,
- "sock_test_client [OPTIONS] <ipaddr> <port>\n"
+ "vcl_test_client [OPTIONS] <ipaddr> <port>\n"
" OPTIONS\n"
" -h Print this message and exit.\n"
" -6 Use IPv6\n"
@@ -735,7 +728,7 @@
static void
vtc_process_opts (vcl_test_client_main_t * vcm, int argc, char **argv)
{
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
int c, v;
opterr = 0;
@@ -747,18 +740,18 @@
break;
case 's':
- if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sockets) != 1)
- if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sockets) != 1)
+ if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1)
+ if (sscanf (optarg, "%u", &ctrl->cfg.num_test_sessions) != 1)
{
vtwrn ("Invalid value for option -%c!", c);
print_usage_and_exit ();
}
- if (!ctrl->cfg.num_test_sockets ||
- (ctrl->cfg.num_test_sockets > FD_SETSIZE))
+ if (!ctrl->cfg.num_test_sessions ||
+ (ctrl->cfg.num_test_sessions > FD_SETSIZE))
{
- vtwrn ("Invalid number of sockets (%d) specified for option -%c!"
+ vtwrn ("Invalid number of sessions (%d) specified for option -%c!"
"\n Valid range is 1 - %d",
- ctrl->cfg.num_test_sockets, c, FD_SETSIZE);
+ ctrl->cfg.num_test_sessions, c, FD_SETSIZE);
print_usage_and_exit ();
}
break;
@@ -774,7 +767,7 @@
break;
case 'X':
- vcm->post_test = SOCK_TEST_TYPE_EXIT;
+ vcm->post_test = VCL_TEST_TYPE_EXIT;
break;
case 'E':
@@ -785,20 +778,20 @@
print_usage_and_exit ();
}
strcpy (ctrl->txbuf, optarg);
- ctrl->cfg.test = SOCK_TEST_TYPE_ECHO;
+ ctrl->cfg.test = VCL_TEST_TYPE_ECHO;
break;
case 'I':
- if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sockets) != 1)
- if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sockets) != 1)
+ if (sscanf (optarg, "0x%x", &ctrl->cfg.num_test_sessions) != 1)
+ if (sscanf (optarg, "%d", &ctrl->cfg.num_test_sessions) != 1)
{
vtwrn ("Invalid value for option -%c!", c);
print_usage_and_exit ();
}
- if (ctrl->cfg.num_test_sockets > SOCK_TEST_CFG_MAX_TEST_SCKTS)
+ if (ctrl->cfg.num_test_sessions > VCL_TEST_CFG_MAX_TEST_SESS)
{
- vtwrn ("value greater than max number test sockets (%d)!",
- SOCK_TEST_CFG_MAX_TEST_SCKTS);
+ vtwrn ("value greater than max number test sessions (%d)!",
+ VCL_TEST_CFG_MAX_TEST_SESS);
print_usage_and_exit ();
}
break;
@@ -820,17 +813,17 @@
vtwrn ("Invalid value for option -%c!", c);
print_usage_and_exit ();
}
- if (ctrl->cfg.rxbuf_size >= SOCK_TEST_CFG_BUF_SIZE_MIN)
+ if (ctrl->cfg.rxbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
{
ctrl->rxbuf_size = ctrl->cfg.rxbuf_size;
- sock_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
- (uint8_t **) & ctrl->rxbuf,
- &ctrl->rxbuf_size);
+ vcl_test_buf_alloc (&ctrl->cfg, 1 /* is_rxbuf */ ,
+ (uint8_t **) & ctrl->rxbuf,
+ &ctrl->rxbuf_size);
}
else
{
vtwrn ("rxbuf size (%lu) less than minumum (%u)",
- ctrl->cfg.rxbuf_size, SOCK_TEST_CFG_BUF_SIZE_MIN);
+ ctrl->cfg.rxbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
print_usage_and_exit ();
}
@@ -843,29 +836,29 @@
vtwrn ("Invalid value for option -%c!", c);
print_usage_and_exit ();
}
- if (ctrl->cfg.txbuf_size >= SOCK_TEST_CFG_BUF_SIZE_MIN)
+ if (ctrl->cfg.txbuf_size >= VCL_TEST_CFG_BUF_SIZE_MIN)
{
ctrl->txbuf_size = ctrl->cfg.txbuf_size;
- sock_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
- (uint8_t **) & ctrl->txbuf,
- &ctrl->txbuf_size);
+ vcl_test_buf_alloc (&ctrl->cfg, 0 /* is_rxbuf */ ,
+ (uint8_t **) & ctrl->txbuf,
+ &ctrl->txbuf_size);
ctrl->cfg.total_bytes =
ctrl->cfg.num_writes * ctrl->cfg.txbuf_size;
}
else
{
vtwrn ("txbuf size (%lu) less than minumum (%u)!",
- ctrl->cfg.txbuf_size, SOCK_TEST_CFG_BUF_SIZE_MIN);
+ ctrl->cfg.txbuf_size, VCL_TEST_CFG_BUF_SIZE_MIN);
print_usage_and_exit ();
}
break;
case 'U':
- ctrl->cfg.test = SOCK_TEST_TYPE_UNI;
+ ctrl->cfg.test = VCL_TEST_TYPE_UNI;
break;
case 'B':
- ctrl->cfg.test = SOCK_TEST_TYPE_BI;
+ ctrl->cfg.test = VCL_TEST_TYPE_BI;
break;
case 'V':
@@ -937,10 +930,10 @@
}
static void
-vtc_read_user_input (sock_test_socket_t * ctrl)
+vtc_read_user_input (vcl_test_session_t * ctrl)
{
printf ("\nType some characters and hit <return>\n"
- "('" SOCK_TEST_TOKEN_HELP "' for help): ");
+ "('" VCL_TEST_TOKEN_HELP "' for help): ");
if (fgets (ctrl->txbuf, ctrl->txbuf_size, stdin) != NULL)
{
@@ -960,18 +953,17 @@
vtc_ctrl_session_exit (void)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
int verbose = ctrl->cfg.verbose;
- ctrl->cfg.test = SOCK_TEST_TYPE_EXIT;
+ ctrl->cfg.test = VCL_TEST_TYPE_EXIT;
if (verbose)
{
vtinf ("(fd %d): Sending exit cfg to server...", ctrl->fd);
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
}
(void) vcl_test_write (ctrl->fd, (uint8_t *) & ctrl->cfg,
sizeof (ctrl->cfg), &ctrl->stats, verbose);
- vtinf ("So long and thanks for all the fish!\n\n");
sleep (1);
}
@@ -979,12 +971,12 @@
main (int argc, char **argv)
{
vcl_test_client_main_t *vcm = &vcl_client_main;
- sock_test_socket_t *ctrl = &vcm->ctrl_socket;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
int rv, errno_val;
vcm->n_workers = 1;
- sock_test_cfg_init (&ctrl->cfg);
- sock_test_socket_buf_alloc (ctrl);
+ vcl_test_cfg_init (&ctrl->cfg);
+ vcl_test_session_buf_alloc (ctrl);
vtc_process_opts (vcm, argc, argv);
vcm->workers = calloc (vcm->n_workers, sizeof (vcl_test_client_worker_t));
@@ -1000,63 +992,63 @@
rv = vppcom_session_connect (ctrl->fd, &vcm->server_endpt);
if (rv)
vtfail ("vppcom_session_connect()", rv);
- vtinf ("(fd %d): Control socket connected.", ctrl->fd);
+ vtinf ("Control session (fd %d) connected.", ctrl->fd);
rv = vtc_cfg_sync (ctrl);
if (rv)
vtfail ("vtc_cfg_sync()", rv);
- ctrl->cfg.ctrl_handle = ((sock_test_cfg_t *) ctrl->rxbuf)->ctrl_handle;
+ ctrl->cfg.ctrl_handle = ((vcl_test_cfg_t *) ctrl->rxbuf)->ctrl_handle;
memset (&ctrl->stats, 0, sizeof (ctrl->stats));
- while (ctrl->cfg.test != SOCK_TEST_TYPE_EXIT)
+ while (ctrl->cfg.test != VCL_TEST_TYPE_EXIT)
{
if (vcm->dump_cfg)
{
- sock_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
+ vcl_test_cfg_dump (&ctrl->cfg, 1 /* is_client */ );
vcm->dump_cfg = 0;
}
switch (ctrl->cfg.test)
{
- case SOCK_TEST_TYPE_ECHO:
+ case VCL_TEST_TYPE_ECHO:
vtc_echo_client (vcm);
break;
- case SOCK_TEST_TYPE_UNI:
- case SOCK_TEST_TYPE_BI:
+ case VCL_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
vtc_stream_client (vcm);
break;
- case SOCK_TEST_TYPE_EXIT:
+ case VCL_TEST_TYPE_EXIT:
continue;
- case SOCK_TEST_TYPE_NONE:
+ case VCL_TEST_TYPE_NONE:
default:
break;
}
switch (vcm->post_test)
{
- case SOCK_TEST_TYPE_EXIT:
+ case VCL_TEST_TYPE_EXIT:
switch (ctrl->cfg.test)
{
- case SOCK_TEST_TYPE_EXIT:
- case SOCK_TEST_TYPE_UNI:
- case SOCK_TEST_TYPE_BI:
- case SOCK_TEST_TYPE_ECHO:
- ctrl->cfg.test = SOCK_TEST_TYPE_EXIT;
+ case VCL_TEST_TYPE_EXIT:
+ case VCL_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
+ case VCL_TEST_TYPE_ECHO:
+ ctrl->cfg.test = VCL_TEST_TYPE_EXIT;
continue;
- case SOCK_TEST_TYPE_NONE:
+ case VCL_TEST_TYPE_NONE:
default:
break;
}
break;
- case SOCK_TEST_TYPE_NONE:
- case SOCK_TEST_TYPE_ECHO:
- case SOCK_TEST_TYPE_UNI:
- case SOCK_TEST_TYPE_BI:
+ case VCL_TEST_TYPE_NONE:
+ case VCL_TEST_TYPE_ECHO:
+ case VCL_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
default:
break;
}
diff --git a/src/vcl/vcl_test_server.c b/src/vcl/vcl_test_server.c
index 2913452..54f164e 100644
--- a/src/vcl/vcl_test_server.c
+++ b/src/vcl/vcl_test_server.c
@@ -34,8 +34,8 @@
int fd;
uint8_t *buf;
uint32_t buf_size;
- sock_test_cfg_t cfg;
- sock_test_stats_t stats;
+ vcl_test_cfg_t cfg;
+ vcl_test_stats_t stats;
vppcom_endpt_t endpt;
uint8_t ip[16];
vppcom_data_segments_t ds;
@@ -50,15 +50,12 @@
vppcom_endpt_t endpt;
} vcl_test_server_cfg_t;
-#define SOCK_SERVER_MAX_TEST_CONN 16
-#define SOCK_SERVER_MAX_EPOLL_EVENTS 16
-
typedef struct
{
uint32_t wrk_index;
int listen_fd;
int epfd;
- struct epoll_event wait_events[SOCK_SERVER_MAX_EPOLL_EVENTS];
+ struct epoll_event wait_events[VCL_TEST_CFG_MAX_EPOLL_EVENTS];
size_t conn_pool_size;
vcl_test_server_conn_t *conn_pool;
int nfds;
@@ -78,7 +75,7 @@
static __thread int __wrk_index = 0;
-static vcl_test_server_main_t sock_server_main;
+static vcl_test_server_main_t vcl_server_main;
static inline void
conn_pool_expand (vcl_test_server_worker_t * wrk, size_t expand_size)
@@ -94,9 +91,9 @@
{
vcl_test_server_conn_t *conn = &conn_pool[i];
memset (conn, 0, sizeof (*conn));
- sock_test_cfg_init (&conn->cfg);
- sock_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
- &conn->buf, &conn->buf_size);
+ vcl_test_cfg_init (&conn->cfg);
+ vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
+ &conn->buf, &conn->buf_size);
conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
}
@@ -143,18 +140,17 @@
}
static inline void
-sync_config_and_reply (vcl_test_server_conn_t * conn,
- sock_test_cfg_t * rx_cfg)
+sync_config_and_reply (vcl_test_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
{
conn->cfg = *rx_cfg;
- sock_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
- &conn->buf, &conn->buf_size);
+ vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
+ &conn->buf, &conn->buf_size);
conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
if (conn->cfg.verbose)
{
vtinf ("(fd %d): Replying to cfg message!\n", conn->fd);
- sock_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
+ vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
}
(void) vcl_test_write (conn->fd, (uint8_t *) & conn->cfg,
sizeof (conn->cfg), NULL, conn->cfg.verbose);
@@ -162,60 +158,62 @@
static void
vts_server_start_stop (vcl_test_server_worker_t * wrk,
- vcl_test_server_conn_t * conn,
- sock_test_cfg_t * rx_cfg)
+ vcl_test_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
{
- u8 is_bi = rx_cfg->test == SOCK_TEST_TYPE_BI;
- int client_fd = conn->fd, i;
+ u8 is_bi = rx_cfg->test == VCL_TEST_TYPE_BI;
vcl_test_server_conn_t *tc;
char buf[64];
+ int i;
if (rx_cfg->ctrl_handle == conn->fd)
{
- clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
-
for (i = 0; i < wrk->conn_pool_size; i++)
{
tc = &wrk->conn_pool[i];
if (tc->cfg.ctrl_handle != conn->fd)
continue;
- sock_test_stats_accumulate (&conn->stats, &tc->stats);
-
+ vcl_test_stats_accumulate (&conn->stats, &tc->stats);
+ if (vcl_comp_tspec (&conn->stats.stop, &tc->stats.stop) < 0)
+ conn->stats.stop = tc->stats.stop;
+ /* Client delays sending of disconnect */
+ conn->stats.stop.tv_sec -= VCL_TEST_DELAY_DISCONNECT;
if (conn->cfg.verbose)
{
sprintf (buf, "SERVER (fd %d) RESULTS", tc->fd);
- sock_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
- is_bi /* show tx */ , conn->cfg.verbose);
+ vcl_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
+ is_bi /* show tx */ , conn->cfg.verbose);
}
}
- sock_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
- is_bi /* show_tx */ , conn->cfg.verbose);
- sock_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
+ vcl_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
+ is_bi /* show_tx */ , conn->cfg.verbose);
+ vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
if (conn->cfg.verbose)
{
- vtinf (" sock server main\n"
- SOCK_TEST_SEPARATOR_STRING
+ vtinf (" vcl server main\n"
+ VCL_TEST_SEPARATOR_STRING
" buf: %p\n"
" buf size: %u (0x%08x)\n"
- SOCK_TEST_SEPARATOR_STRING,
+ VCL_TEST_SEPARATOR_STRING,
conn->buf, conn->buf_size, conn->buf_size);
}
sync_config_and_reply (conn, rx_cfg);
- vtinf ("(fd %d): %s-directional Stream Test Complete!\n"
- SOCK_TEST_BANNER_STRING "\n", conn->fd, is_bi ? "Bi" : "Uni");
memset (&conn->stats, 0, sizeof (conn->stats));
}
else
{
- vtinf (SOCK_TEST_BANNER_STRING "(fd %d): %s-directional Stream Test!\n"
- " Sending client the test cfg to start streaming data...\n",
- client_fd, is_bi ? "Bi" : "Uni");
-
if (rx_cfg->ctrl_handle == ~0)
- rx_cfg->ctrl_handle = conn->fd;
+ {
+ rx_cfg->ctrl_handle = conn->fd;
+ vtinf ("Set control fd %d for test!", conn->fd);
+ }
+ else
+ {
+ vtinf ("Starting %s-directional Stream Test (fd %d)!",
+ is_bi ? "Bi" : "Uni", conn->fd);
+ }
sync_config_and_reply (conn, rx_cfg);
@@ -228,12 +226,12 @@
static inline void
vts_server_rx (vcl_test_server_conn_t * conn, int rx_bytes)
{
- vcl_test_server_main_t *vts = &sock_server_main;
+ vcl_test_server_main_t *vsm = &vcl_server_main;
int client_fd = conn->fd;
- if (conn->cfg.test == SOCK_TEST_TYPE_BI)
+ if (conn->cfg.test == VCL_TEST_TYPE_BI)
{
- if (vts->use_ds)
+ if (vsm->use_ds)
{
(void) vcl_test_write (client_fd, conn->ds[0].data, conn->ds[0].len,
&conn->stats, conn->cfg.verbose);
@@ -247,7 +245,7 @@
conn->cfg.verbose);
}
- if (vts->use_ds)
+ if (vsm->use_ds)
vppcom_session_free_segments (conn->fd, conn->ds);
if (conn->stats.rx_bytes >= conn->cfg.total_bytes)
@@ -257,10 +255,10 @@
static void
vts_server_echo (vcl_test_server_conn_t * conn, int rx_bytes)
{
- vcl_test_server_main_t *vts = &sock_server_main;
+ vcl_test_server_main_t *vsm = &vcl_server_main;
int tx_bytes, nbytes, pos;
- if (vts->use_ds)
+ if (vsm->use_ds)
vppcom_data_segment_copy (conn->buf, conn->ds, rx_bytes);
/* If it looks vaguely like a string, make sure it's terminated */
@@ -278,11 +276,12 @@
vtinf ("(fd %d): TX (%d bytes) - '%s'", conn->fd, tx_bytes, conn->buf);
}
-static inline void
+static void
vts_new_client (vcl_test_server_worker_t * wrk)
{
- int client_fd;
vcl_test_server_conn_t *conn;
+ struct epoll_event ev;
+ int rv, client_fd;
conn = conn_pool_alloc (wrk);
if (!conn)
@@ -297,32 +296,26 @@
vterr ("vppcom_session_accept()", client_fd);
return;
}
+ conn->fd = client_fd;
vtinf ("Got a connection -- fd = %d (0x%08x)!", client_fd, client_fd);
- conn->fd = client_fd;
-
- {
- struct epoll_event ev;
- int rv;
-
- ev.events = EPOLLIN;
- ev.data.u64 = conn - wrk->conn_pool;
- rv = vppcom_epoll_ctl (wrk->epfd, EPOLL_CTL_ADD, client_fd, &ev);
- if (rv < 0)
- {
- vterr ("vppcom_epoll_ctl()", rv);
- return;
- }
- wrk->nfds++;
- }
+ ev.events = EPOLLIN;
+ ev.data.u64 = conn - wrk->conn_pool;
+ rv = vppcom_epoll_ctl (wrk->epfd, EPOLL_CTL_ADD, client_fd, &ev);
+ if (rv < 0)
+ {
+ vterr ("vppcom_epoll_ctl()", rv);
+ return;
+ }
+ wrk->nfds++;
}
-void
+static void
print_usage_and_exit (void)
{
fprintf (stderr,
- "sock_test_server [OPTIONS] <port>\n"
+ "vcl_test_server [OPTIONS] <port>\n"
" OPTIONS\n"
" -h Print this message and exit.\n"
" -6 Use IPv6\n"
@@ -332,71 +325,71 @@
}
static void
-vcl_test_init_endpoint_addr (vcl_test_server_main_t * ssm)
+vcl_test_init_endpoint_addr (vcl_test_server_main_t * vsm)
{
- struct sockaddr_storage *servaddr = &ssm->servaddr;
+ struct sockaddr_storage *servaddr = &vsm->servaddr;
memset (servaddr, 0, sizeof (*servaddr));
- if (ssm->cfg.address_ip6)
+ if (vsm->cfg.address_ip6)
{
struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) servaddr;
server_addr->sin6_family = AF_INET6;
server_addr->sin6_addr = in6addr_any;
- server_addr->sin6_port = htons (ssm->cfg.port);
+ server_addr->sin6_port = htons (vsm->cfg.port);
}
else
{
struct sockaddr_in *server_addr = (struct sockaddr_in *) servaddr;
server_addr->sin_family = AF_INET;
server_addr->sin_addr.s_addr = htonl (INADDR_ANY);
- server_addr->sin_port = htons (ssm->cfg.port);
+ server_addr->sin_port = htons (vsm->cfg.port);
}
- if (ssm->cfg.address_ip6)
+ if (vsm->cfg.address_ip6)
{
struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) servaddr;
- ssm->cfg.endpt.is_ip4 = 0;
- ssm->cfg.endpt.ip = (uint8_t *) & server_addr->sin6_addr;
- ssm->cfg.endpt.port = (uint16_t) server_addr->sin6_port;
+ vsm->cfg.endpt.is_ip4 = 0;
+ vsm->cfg.endpt.ip = (uint8_t *) & server_addr->sin6_addr;
+ vsm->cfg.endpt.port = (uint16_t) server_addr->sin6_port;
}
else
{
struct sockaddr_in *server_addr = (struct sockaddr_in *) servaddr;
- ssm->cfg.endpt.is_ip4 = 1;
- ssm->cfg.endpt.ip = (uint8_t *) & server_addr->sin_addr;
- ssm->cfg.endpt.port = (uint16_t) server_addr->sin_port;
+ vsm->cfg.endpt.is_ip4 = 1;
+ vsm->cfg.endpt.ip = (uint8_t *) & server_addr->sin_addr;
+ vsm->cfg.endpt.port = (uint16_t) server_addr->sin_port;
}
}
static void
-vcl_test_server_process_opts (vcl_test_server_main_t * ssm, int argc,
+vcl_test_server_process_opts (vcl_test_server_main_t * vsm, int argc,
char **argv)
{
int v, c;
- ssm->cfg.proto = VPPCOM_PROTO_TCP;
+ vsm->cfg.proto = VPPCOM_PROTO_TCP;
opterr = 0;
while ((c = getopt (argc, argv, "6Dsw:")) != -1)
switch (c)
{
case '6':
- ssm->cfg.address_ip6 = 1;
+ vsm->cfg.address_ip6 = 1;
break;
case 'D':
- ssm->cfg.proto = VPPCOM_PROTO_UDP;
+ vsm->cfg.proto = VPPCOM_PROTO_UDP;
break;
case 'w':
v = atoi (optarg);
if (v > 1)
- ssm->cfg.workers = v;
+ vsm->cfg.workers = v;
else
vtwrn ("Invalid number of workers %d", v);
break;
case 's':
- ssm->use_ds = 1;
+ vsm->use_ds = 1;
break;
case '?':
switch (optopt)
@@ -420,24 +413,24 @@
}
if (sscanf (argv[optind], "%d", &v) == 1)
- ssm->cfg.port = (uint16_t) v;
+ vsm->cfg.port = (uint16_t) v;
else
{
fprintf (stderr, "SERVER: ERROR: Invalid port (%s)!\n", argv[optind]);
print_usage_and_exit ();
}
- vcl_test_init_endpoint_addr (ssm);
+ vcl_test_init_endpoint_addr (vsm);
}
int
-vts_handle_cfg (vcl_test_server_worker_t * wrk, sock_test_cfg_t * rx_cfg,
+vts_handle_cfg (vcl_test_server_worker_t * wrk, vcl_test_cfg_t * rx_cfg,
vcl_test_server_conn_t * conn, int rx_bytes)
{
if (rx_cfg->verbose)
{
vtinf ("(fd %d): Received a cfg msg!", conn->fd);
- sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
+ vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
}
if (rx_bytes != sizeof (*rx_cfg))
@@ -449,7 +442,7 @@
if (conn->cfg.verbose)
{
vtinf ("(fd %d): Replying to cfg msg", conn->fd);
- sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
+ vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
}
vcl_test_write (conn->fd, (uint8_t *) & conn->cfg,
sizeof (conn->cfg), NULL, conn->cfg.verbose);
@@ -458,18 +451,19 @@
switch (rx_cfg->test)
{
- case SOCK_TEST_TYPE_NONE:
- case SOCK_TEST_TYPE_ECHO:
+ case VCL_TEST_TYPE_NONE:
+ case VCL_TEST_TYPE_ECHO:
sync_config_and_reply (conn, rx_cfg);
break;
- case SOCK_TEST_TYPE_BI:
- case SOCK_TEST_TYPE_UNI:
+ case VCL_TEST_TYPE_BI:
+ case VCL_TEST_TYPE_UNI:
vts_server_start_stop (wrk, conn, rx_cfg);
break;
- case SOCK_TEST_TYPE_EXIT:
- vtinf ("Have a great day conn %d (closing)!", conn->fd);
+ case VCL_TEST_TYPE_EXIT:
+ vtinf ("Session fd %d closing!", conn->fd);
+ clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
vppcom_session_close (conn->fd);
conn_pool_free (conn);
wrk->nfds--;
@@ -477,7 +471,7 @@
default:
vtwrn ("Unknown test type %d", rx_cfg->test);
- sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
+ vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
break;
}
@@ -487,7 +481,7 @@
static void
vts_worker_init (vcl_test_server_worker_t * wrk)
{
- vcl_test_server_main_t *ssm = &sock_server_main;
+ vcl_test_server_main_t *vsm = &vcl_server_main;
struct epoll_event listen_ev;
int rv;
@@ -495,21 +489,21 @@
vtinf ("Initializing worker ...");
- conn_pool_expand (wrk, SOCK_SERVER_MAX_TEST_CONN + 1);
+ conn_pool_expand (wrk, VCL_TEST_CFG_MAX_TEST_SESS + 1);
if (wrk->wrk_index)
if (vppcom_worker_register ())
vtfail ("vppcom_worker_register()", 1);
- wrk->listen_fd = vppcom_session_create (ssm->cfg.proto,
+ wrk->listen_fd = vppcom_session_create (vsm->cfg.proto,
0 /* is_nonblocking */ );
if (wrk->listen_fd < 0)
vtfail ("vppcom_session_create()", wrk->listen_fd);
- rv = vppcom_session_bind (wrk->listen_fd, &ssm->cfg.endpt);
+ rv = vppcom_session_bind (wrk->listen_fd, &vsm->cfg.endpt);
if (rv < 0)
vtfail ("vppcom_session_bind()", rv);
- if (!(ssm->cfg.proto == VPPCOM_PROTO_UDP))
+ if (!(vsm->cfg.proto == VPPCOM_PROTO_UDP))
{
rv = vppcom_session_listen (wrk->listen_fd, 10);
if (rv < 0)
@@ -527,41 +521,39 @@
if (rv < 0)
vtfail ("vppcom_epoll_ctl", rv);
- ssm->active_workers += 1;
- vtinf ("Waiting for a client to connect on port %d ...", ssm->cfg.port);
+ vsm->active_workers += 1;
+ vtinf ("Waiting for a client to connect on port %d ...", vsm->cfg.port);
}
static int
vts_conn_expect_config (vcl_test_server_conn_t * conn)
{
- if (conn->cfg.test == SOCK_TEST_TYPE_ECHO)
+ if (conn->cfg.test == VCL_TEST_TYPE_ECHO)
return 1;
return (conn->stats.rx_bytes < 128
- || conn->stats.rx_bytes >= conn->cfg.total_bytes);
+ || conn->stats.rx_bytes > conn->cfg.total_bytes);
}
-static sock_test_cfg_t *
+static vcl_test_cfg_t *
vts_conn_read_config (vcl_test_server_conn_t * conn)
{
- vcl_test_server_main_t *vts = &sock_server_main;
+ vcl_test_server_main_t *vsm = &vcl_server_main;
- if (vts->use_ds)
+ if (vsm->use_ds)
{
/* We could avoid the copy if the first segment is big enough but this
* just simplifies things */
- vppcom_data_segment_copy (conn->buf, conn->ds,
- sizeof (sock_test_cfg_t));
- vppcom_session_free_segments (conn->fd, conn->ds);
+ vppcom_data_segment_copy (conn->buf, conn->ds, sizeof (vcl_test_cfg_t));
}
- return (sock_test_cfg_t *) conn->buf;
+ return (vcl_test_cfg_t *) conn->buf;
}
static inline int
vts_conn_read (vcl_test_server_conn_t * conn)
{
- vcl_test_server_main_t *vts = &sock_server_main;
- if (vts->use_ds)
+ vcl_test_server_main_t *vsm = &vcl_server_main;
+ if (vsm->use_ds)
return vcl_test_read_ds (conn->fd, conn->ds, &conn->stats);
else
return vcl_test_read (conn->fd, conn->buf, conn->buf_size, &conn->stats);
@@ -570,9 +562,9 @@
static inline int
vts_conn_has_ascii (vcl_test_server_conn_t * conn)
{
- vcl_test_server_main_t *vts = &sock_server_main;
+ vcl_test_server_main_t *vsm = &vcl_server_main;
- if (vts->use_ds)
+ if (vsm->use_ds)
return isascii (conn->ds[0].data[0]);
else
return isascii (conn->buf[0]);
@@ -581,11 +573,11 @@
static void *
vts_worker_loop (void *arg)
{
- vcl_test_server_main_t *ssm = &sock_server_main;
+ vcl_test_server_main_t *vsm = &vcl_server_main;
vcl_test_server_worker_t *wrk = arg;
vcl_test_server_conn_t *conn;
int i, rx_bytes, num_ev;
- sock_test_cfg_t *rx_cfg;
+ vcl_test_cfg_t *rx_cfg;
if (wrk->wrk_index)
vts_worker_init (wrk);
@@ -593,7 +585,7 @@
while (1)
{
num_ev = vppcom_epoll_wait (wrk->epfd, wrk->wait_events,
- SOCK_SERVER_MAX_EPOLL_EVENTS, 60000.0);
+ VCL_TEST_CFG_MAX_EPOLL_EVENTS, 60000.0);
if (num_ev < 0)
{
vterr ("vppcom_epoll_wait()", num_ev);
@@ -643,8 +635,10 @@
if (vts_conn_expect_config (conn))
{
rx_cfg = vts_conn_read_config (conn);
- if (rx_cfg->magic == SOCK_TEST_CFG_CTRL_MAGIC)
+ if (rx_cfg->magic == VCL_TEST_CFG_CTRL_MAGIC)
{
+ if (vsm->use_ds)
+ vppcom_session_free_segments (conn->fd, conn->ds);
vts_handle_cfg (wrk, rx_cfg, conn, rx_bytes);
if (!wrk->nfds)
{
@@ -654,8 +648,8 @@
continue;
}
}
- if ((conn->cfg.test == SOCK_TEST_TYPE_UNI)
- || (conn->cfg.test == SOCK_TEST_TYPE_BI))
+ if ((conn->cfg.test == VCL_TEST_TYPE_UNI)
+ || (conn->cfg.test == VCL_TEST_TYPE_BI))
{
vts_server_rx (conn, rx_bytes);
if (vppcom_session_attr (conn->fd, VPPCOM_ATTR_GET_NREAD, 0,
@@ -681,24 +675,24 @@
}
fail:
- ssm->worker_fails -= 1;
+ vsm->worker_fails -= 1;
done:
vppcom_session_close (wrk->listen_fd);
if (wrk->conn_pool)
free (wrk->conn_pool);
- ssm->active_workers -= 1;
+ vsm->active_workers -= 1;
return 0;
}
int
main (int argc, char **argv)
{
- vcl_test_server_main_t *vsm = &sock_server_main;
+ vcl_test_server_main_t *vsm = &vcl_server_main;
int rv, i;
clib_mem_init_thread_safe (0, 64 << 20);
- vsm->cfg.port = SOCK_TEST_SERVER_PORT;
+ vsm->cfg.port = VCL_TEST_SERVER_PORT;
vsm->cfg.workers = 1;
vsm->active_workers = 0;
vcl_test_server_process_opts (vsm, argc, argv);