aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/hs_apps/vcl/vcl_test.h62
-rw-r--r--src/plugins/hs_apps/vcl/vcl_test_client.c28
-rw-r--r--src/plugins/hs_apps/vcl/vcl_test_server.c129
3 files changed, 80 insertions, 139 deletions
diff --git a/src/plugins/hs_apps/vcl/vcl_test.h b/src/plugins/hs_apps/vcl/vcl_test.h
index 5b3ae653860..386e9686ef2 100644
--- a/src/plugins/hs_apps/vcl/vcl_test.h
+++ b/src/plugins/hs_apps/vcl/vcl_test.h
@@ -123,6 +123,8 @@ typedef struct
typedef struct
{
+ uint8_t is_alloc;
+ uint8_t is_open;
int fd;
uint32_t txbuf_size;
char *txbuf;
@@ -131,9 +133,11 @@ typedef struct
vcl_test_cfg_t cfg;
vcl_test_stats_t stats;
int session_index;
+ vppcom_endpt_t endpt;
+ uint8_t ip[16];
+ vppcom_data_segment_t ds[2];
} vcl_test_session_t;
-
/*
* TLS server cert and keys to be used for testing only
*/
@@ -414,31 +418,26 @@ vcl_comp_tspec (struct timespec *a, struct timespec *b)
}
static inline int
-vcl_test_read (int fd, uint8_t * buf, uint32_t nbytes,
- vcl_test_stats_t * stats)
+vcl_test_read (vcl_test_session_t *ts, void *buf, uint32_t nbytes)
{
+ vcl_test_stats_t *stats = &ts->stats;
int rx_bytes;
do
{
- if (stats)
- stats->rx_xacts++;
- rx_bytes = vppcom_session_read (fd, buf, nbytes);
+ stats->rx_xacts++;
+ rx_bytes = vppcom_session_read (ts->fd, buf, nbytes);
if (rx_bytes < 0)
{
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))));
@@ -447,36 +446,32 @@ vcl_test_read (int fd, uint8_t * buf, uint32_t nbytes,
{
vterr ("vppcom_session_read()", -errno);
}
- else if (stats)
+ else
stats->rx_bytes += rx_bytes;
return (rx_bytes);
}
static inline int
-vcl_test_read_ds (int fd, vppcom_data_segment_t * ds,
- vcl_test_stats_t * stats)
+vcl_test_read_ds (vcl_test_session_t *ts)
{
+ vcl_test_stats_t *stats = &ts->stats;
int rx_bytes;
do
{
- if (stats)
- stats->rx_xacts++;
- rx_bytes = vppcom_session_read_segments (fd, ds, 2, ~0);
+ stats->rx_xacts++;
+ rx_bytes = vppcom_session_read_segments (ts->fd, ts->ds, 2, ~0);
if (rx_bytes < 0)
{
errno = -rx_bytes;
rx_bytes = -1;
}
- if (stats)
- {
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))));
@@ -485,27 +480,26 @@ vcl_test_read_ds (int fd, vppcom_data_segment_t * ds,
{
vterr ("vppcom_session_read()", -errno);
}
- else if (stats)
+ else
stats->rx_bytes += rx_bytes;
return (rx_bytes);
}
static inline int
-vcl_test_write (int fd, uint8_t * buf, uint32_t nbytes,
- vcl_test_stats_t * stats, uint32_t verbose)
+vcl_test_write (vcl_test_session_t *ts, void *buf, uint32_t nbytes)
{
int tx_bytes = 0, nbytes_left = nbytes, rv;
+ vcl_test_stats_t *stats = &ts->stats;
do
{
- if (stats)
- stats->tx_xacts++;
- rv = vppcom_session_write (fd, buf, nbytes_left);
+ stats->tx_xacts++;
+ rv = vppcom_session_write (ts->fd, buf, nbytes_left);
if (rv < 0)
{
errno = -rv;
- if ((errno == EAGAIN || errno == EWOULDBLOCK) && stats)
+ if ((errno == EAGAIN || errno == EWOULDBLOCK))
stats->tx_eagain++;
break;
}
@@ -513,9 +507,7 @@ vcl_test_write (int fd, uint8_t * buf, uint32_t nbytes,
nbytes_left = nbytes_left - rv;
buf += rv;
- if (stats)
- stats->tx_incomp++;
-
+ stats->tx_incomp++;
}
while (tx_bytes != nbytes);
@@ -523,7 +515,7 @@ vcl_test_write (int fd, uint8_t * buf, uint32_t nbytes,
{
vterr ("vpcom_session_write", -errno);
}
- else if (stats)
+ else
stats->tx_bytes += tx_bytes;
return (tx_bytes);
diff --git a/src/plugins/hs_apps/vcl/vcl_test_client.c b/src/plugins/hs_apps/vcl/vcl_test_client.c
index 6b0953f0f4d..0033ae6a30d 100644
--- a/src/plugins/hs_apps/vcl/vcl_test_client.c
+++ b/src/plugins/hs_apps/vcl/vcl_test_client.c
@@ -75,16 +75,15 @@ vtc_cfg_sync (vcl_test_session_t * ts)
vtinf ("(fd %d): Sending config to server.", ts->fd);
vcl_test_cfg_dump (&ts->cfg, 1 /* is_client */ );
}
- tx_bytes = vcl_test_write (ts->fd, (uint8_t *) & ts->cfg,
- sizeof (ts->cfg), NULL, ts->cfg.verbose);
+ tx_bytes = vcl_test_write (ts, (uint8_t *) &ts->cfg, sizeof (ts->cfg));
if (tx_bytes < 0)
{
vtwrn ("(fd %d): write test cfg failed (%d)!", ts->fd, tx_bytes);
return tx_bytes;
}
- rx_bytes = vcl_test_read (ts->fd, (uint8_t *) ts->rxbuf,
- sizeof (vcl_test_cfg_t), NULL);
+ rx_bytes =
+ vcl_test_read (ts, (uint8_t *) ts->rxbuf, sizeof (vcl_test_cfg_t));
if (rx_bytes < 0)
return rx_bytes;
@@ -432,7 +431,7 @@ vtc_worker_loop (void *arg)
vcl_test_client_main_t *vcm = &vcl_client_main;
vcl_test_session_t *ctrl = &vcm->ctrl_session;
vcl_test_client_worker_t *wrk = arg;
- uint32_t n_active_sessions, n_bytes;
+ uint32_t n_active_sessions;
fd_set _wfdset, *wfdset = &_wfdset;
fd_set _rfdset, *rfdset = &_rfdset;
vcl_test_session_t *ts;
@@ -477,18 +476,14 @@ vtc_worker_loop (void *arg)
if (FD_ISSET (vppcom_session_index (ts->fd), rfdset)
&& ts->stats.rx_bytes < ts->cfg.total_bytes)
{
- (void) vcl_test_read (ts->fd, (uint8_t *) ts->rxbuf,
- ts->rxbuf_size, &ts->stats);
+ (void) vcl_test_read (ts, (uint8_t *) ts->rxbuf, ts->rxbuf_size);
}
if (FD_ISSET (vppcom_session_index (ts->fd), wfdset)
&& ts->stats.tx_bytes < ts->cfg.total_bytes)
{
- n_bytes = ts->cfg.txbuf_size;
- if (ts->cfg.test == VCL_TEST_TYPE_ECHO)
- n_bytes = strlen (ctrl->txbuf) + 1;
- rv = vcl_test_write (ts->fd, (uint8_t *) ts->txbuf,
- n_bytes, &ts->stats, ts->cfg.verbose);
+ rv =
+ vcl_test_write (ts, (uint8_t *) ts->txbuf, ts->cfg.txbuf_size);
if (rv < 0)
{
vtwrn ("vppcom_test_write (%d) failed -- aborting test",
@@ -563,16 +558,14 @@ vtc_echo_client (vcl_test_client_main_t * vcm)
cfg->total_bytes = strlen (ctrl->txbuf) + 1;
memset (&ctrl->stats, 0, sizeof (ctrl->stats));
- rv = vcl_test_write (ctrl->fd, (uint8_t *) ctrl->txbuf, cfg->total_bytes,
- &ctrl->stats, ctrl->cfg.verbose);
+ rv = vcl_test_write (ctrl, (uint8_t *) ctrl->txbuf, cfg->total_bytes);
if (rv < 0)
{
vtwrn ("vppcom_test_write (%d) failed ", ctrl->fd);
return;
}
- (void) vcl_test_read (ctrl->fd, (uint8_t *) ctrl->rxbuf, ctrl->rxbuf_size,
- &ctrl->stats);
+ (void) vcl_test_read (ctrl, (uint8_t *) ctrl->rxbuf, ctrl->rxbuf_size);
}
static void
@@ -1062,8 +1055,7 @@ vtc_ctrl_session_exit (void)
vtinf ("(fd %d): Sending exit cfg to server...", ctrl->fd);
if (verbose)
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);
+ (void) vcl_test_write (ctrl, (uint8_t *) &ctrl->cfg, sizeof (ctrl->cfg));
sleep (1);
}
diff --git a/src/plugins/hs_apps/vcl/vcl_test_server.c b/src/plugins/hs_apps/vcl/vcl_test_server.c
index 5b02fc08e8e..b8fa1b7c600 100644
--- a/src/plugins/hs_apps/vcl/vcl_test_server.c
+++ b/src/plugins/hs_apps/vcl/vcl_test_server.c
@@ -30,20 +30,6 @@
typedef struct
{
- uint8_t is_alloc;
- uint8_t is_open;
- int fd;
- uint8_t *buf;
- uint32_t buf_size;
- vcl_test_cfg_t cfg;
- vcl_test_stats_t stats;
- vppcom_endpt_t endpt;
- uint8_t ip[16];
- vppcom_data_segment_t ds[2];
-} vcl_test_server_conn_t;
-
-typedef struct
-{
uint16_t port;
uint32_t address_ip6;
u8 proto;
@@ -58,7 +44,7 @@ typedef struct
int epfd;
struct epoll_event wait_events[VCL_TEST_CFG_MAX_EPOLL_EVENTS];
size_t conn_pool_size;
- vcl_test_server_conn_t *conn_pool;
+ vcl_test_session_t *conn_pool;
int nfds;
pthread_t thread_handle;
} vcl_test_server_worker_t;
@@ -68,7 +54,7 @@ typedef struct
vcl_test_server_cfg_t cfg;
vcl_test_server_worker_t *workers;
- vcl_test_server_conn_t *ctrl;
+ vcl_test_session_t *ctrl;
int ctrl_listen_fd;
struct sockaddr_storage servaddr;
volatile int worker_fails;
@@ -83,7 +69,7 @@ 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)
{
- vcl_test_server_conn_t *conn_pool;
+ vcl_test_session_t *conn_pool;
size_t new_size = wrk->conn_pool_size + expand_size;
int i;
@@ -92,11 +78,11 @@ conn_pool_expand (vcl_test_server_worker_t * wrk, size_t expand_size)
{
for (i = wrk->conn_pool_size; i < new_size; i++)
{
- vcl_test_server_conn_t *conn = &conn_pool[i];
+ vcl_test_session_t *conn = &conn_pool[i];
memset (conn, 0, sizeof (*conn));
vcl_test_cfg_init (&conn->cfg);
- vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
- &conn->buf, &conn->buf_size);
+ vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */,
+ (uint8_t **) &conn->rxbuf, &conn->rxbuf_size);
conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
}
@@ -109,8 +95,8 @@ conn_pool_expand (vcl_test_server_worker_t * wrk, size_t expand_size)
}
}
-static inline vcl_test_server_conn_t *
-conn_pool_alloc (vcl_test_server_worker_t * wrk)
+static inline vcl_test_session_t *
+conn_pool_alloc (vcl_test_server_worker_t *wrk)
{
int i, expand = 0;
@@ -136,18 +122,18 @@ again:
}
static inline void
-conn_pool_free (vcl_test_server_conn_t * conn)
+conn_pool_free (vcl_test_session_t *conn)
{
conn->fd = 0;
conn->is_alloc = 0;
}
static inline void
-sync_config_and_reply (vcl_test_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
+sync_config_and_reply (vcl_test_session_t *conn, vcl_test_cfg_t *rx_cfg)
{
conn->cfg = *rx_cfg;
- vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
- &conn->buf, &conn->buf_size);
+ vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */, (uint8_t **) &conn->rxbuf,
+ &conn->rxbuf_size);
conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
if (conn->cfg.verbose)
@@ -155,12 +141,11 @@ sync_config_and_reply (vcl_test_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
vtinf ("(fd %d): Replying to cfg message!\n", conn->fd);
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);
+ (void) vcl_test_write (conn, &conn->cfg, sizeof (conn->cfg));
}
static void
-vts_session_close (vcl_test_server_conn_t *conn)
+vts_session_close (vcl_test_session_t *conn)
{
if (!conn->is_open)
return;
@@ -169,7 +154,7 @@ vts_session_close (vcl_test_server_conn_t *conn)
}
static void
-vts_session_cleanup (vcl_test_server_conn_t *conn)
+vts_session_cleanup (vcl_test_session_t *conn)
{
vts_session_close (conn);
conn_pool_free (conn);
@@ -178,7 +163,7 @@ vts_session_cleanup (vcl_test_server_conn_t *conn)
static void
vts_wrk_cleanup_all (vcl_test_server_worker_t *wrk)
{
- vcl_test_server_conn_t *conn;
+ vcl_test_session_t *conn;
int i;
for (i = 0; i < wrk->conn_pool_size; i++)
@@ -191,11 +176,11 @@ vts_wrk_cleanup_all (vcl_test_server_worker_t *wrk)
}
static void
-vts_test_cmd (vcl_test_server_worker_t *wrk, vcl_test_server_conn_t *conn,
+vts_test_cmd (vcl_test_server_worker_t *wrk, vcl_test_session_t *conn,
vcl_test_cfg_t *rx_cfg)
{
u8 is_bi = rx_cfg->test == VCL_TEST_TYPE_BI;
- vcl_test_server_conn_t *tc;
+ vcl_test_session_t *tc;
char buf[64];
int i;
@@ -242,12 +227,10 @@ vts_test_cmd (vcl_test_server_worker_t *wrk, vcl_test_server_conn_t *conn,
vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
if (conn->cfg.verbose)
{
- vtinf (" vcl server main\n"
- VCL_TEST_SEPARATOR_STRING
+ vtinf (" vcl server main\n" VCL_TEST_SEPARATOR_STRING
" buf: %p\n"
- " buf size: %u (0x%08x)\n"
- VCL_TEST_SEPARATOR_STRING,
- conn->buf, conn->buf_size, conn->buf_size);
+ " buf size: %u (0x%08x)\n" VCL_TEST_SEPARATOR_STRING,
+ conn->rxbuf, conn->rxbuf_size, conn->rxbuf_size);
}
sync_config_and_reply (conn, rx_cfg);
@@ -273,25 +256,20 @@ vts_test_cmd (vcl_test_server_worker_t *wrk, vcl_test_server_conn_t *conn,
}
static inline void
-vts_server_process_rx (vcl_test_server_conn_t *conn, int rx_bytes)
+vts_server_process_rx (vcl_test_session_t *conn, int rx_bytes)
{
vcl_test_server_main_t *vsm = &vcl_server_main;
- int client_fd = conn->fd;
if (conn->cfg.test == VCL_TEST_TYPE_BI)
{
if (vsm->use_ds)
{
- (void) vcl_test_write (client_fd, conn->ds[0].data, conn->ds[0].len,
- &conn->stats, conn->cfg.verbose);
+ (void) vcl_test_write (conn, conn->ds[0].data, conn->ds[0].len);
if (conn->ds[1].len)
- (void) vcl_test_write (client_fd, conn->ds[1].data,
- conn->ds[1].len, &conn->stats,
- conn->cfg.verbose);
+ (void) vcl_test_write (conn, conn->ds[1].data, conn->ds[1].len);
}
else
- (void) vcl_test_write (client_fd, conn->buf, rx_bytes, &conn->stats,
- conn->cfg.verbose);
+ (void) vcl_test_write (conn, conn->rxbuf, rx_bytes);
}
if (vsm->use_ds)
@@ -302,47 +280,28 @@ vts_server_process_rx (vcl_test_server_conn_t *conn, int rx_bytes)
}
static void
-vts_copy_ds (void *buf, vppcom_data_segment_t * ds, u32 max_bytes)
-{
- uint32_t n_bytes = 0, ds_idx = 0, to_copy;
-
- while (n_bytes < max_bytes)
- {
- to_copy = clib_min (ds[ds_idx].len, max_bytes - n_bytes);
- clib_memcpy_fast (buf + n_bytes, ds[ds_idx].data, to_copy);
- n_bytes += to_copy;
- ds_idx += 1;
- }
-}
-
-static void
-vts_server_echo (vcl_test_server_conn_t * conn, int rx_bytes)
+vts_server_echo (vcl_test_session_t *conn, int rx_bytes)
{
- vcl_test_server_main_t *vsm = &vcl_server_main;
int tx_bytes, nbytes, pos;
- if (vsm->use_ds)
- vts_copy_ds (conn->buf, conn->ds, rx_bytes);
-
/* If it looks vaguely like a string, make sure it's terminated */
- pos = rx_bytes < conn->buf_size ? rx_bytes : conn->buf_size - 1;
- ((char *) conn->buf)[pos] = 0;
- vtinf ("(fd %d): RX (%d bytes) - '%s'", conn->fd, rx_bytes, conn->buf);
+ pos = rx_bytes < conn->rxbuf_size ? rx_bytes : conn->rxbuf_size - 1;
+ ((char *) conn->rxbuf)[pos] = 0;
+ vtinf ("(fd %d): RX (%d bytes) - '%s'", conn->fd, rx_bytes, conn->rxbuf);
if (conn->cfg.verbose)
vtinf ("(fd %d): Echoing back", conn->fd);
- nbytes = strlen ((const char *) conn->buf) + 1;
- tx_bytes = vcl_test_write (conn->fd, conn->buf, nbytes, &conn->stats,
- conn->cfg.verbose);
+ nbytes = strlen ((const char *) conn->rxbuf) + 1;
+ tx_bytes = vcl_test_write (conn, conn->rxbuf, nbytes);
if (tx_bytes >= 0)
- vtinf ("(fd %d): TX (%d bytes) - '%s'", conn->fd, tx_bytes, conn->buf);
+ vtinf ("(fd %d): TX (%d bytes) - '%s'", conn->fd, tx_bytes, conn->rxbuf);
}
-static vcl_test_server_conn_t *
+static vcl_test_session_t *
vts_accept_client (vcl_test_server_worker_t *wrk, int listen_fd)
{
- vcl_test_server_conn_t *conn;
+ vcl_test_session_t *conn;
struct epoll_event ev;
int rv, client_fd;
@@ -520,7 +479,7 @@ vts_clean_connected_listeners (vcl_test_server_worker_t * wrk,
int
vts_handle_ctrl_cfg (vcl_test_server_worker_t *wrk, vcl_test_cfg_t *rx_cfg,
- vcl_test_server_conn_t *conn, int rx_bytes)
+ vcl_test_session_t *conn, int rx_bytes)
{
int listener_fd;
if (rx_cfg->verbose)
@@ -540,8 +499,7 @@ vts_handle_ctrl_cfg (vcl_test_server_worker_t *wrk, vcl_test_cfg_t *rx_cfg,
vtinf ("(fd %d): Replying to cfg msg", conn->fd);
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);
+ vcl_test_write (conn, &conn->cfg, sizeof (conn->cfg));
return -1;
}
@@ -655,13 +613,13 @@ vts_worker_init (vcl_test_server_worker_t * wrk)
}
static inline int
-vts_conn_read (vcl_test_server_conn_t * conn)
+vts_conn_read (vcl_test_session_t *conn)
{
vcl_test_server_main_t *vsm = &vcl_server_main;
if (vsm->use_ds)
- return vcl_test_read_ds (conn->fd, conn->ds, &conn->stats);
+ return vcl_test_read_ds (conn);
else
- return vcl_test_read (conn->fd, conn->buf, conn->buf_size, &conn->stats);
+ return vcl_test_read (conn, conn->rxbuf, conn->rxbuf_size);
}
static void *
@@ -669,7 +627,7 @@ vts_worker_loop (void *arg)
{
vcl_test_server_main_t *vsm = &vcl_server_main;
vcl_test_server_worker_t *wrk = arg;
- vcl_test_server_conn_t *conn;
+ vcl_test_session_t *conn;
int i, rx_bytes, num_ev, listener_fd;
vcl_test_cfg_t *rx_cfg;
@@ -742,9 +700,8 @@ vts_worker_loop (void *arg)
if (!wrk->wrk_index && conn->fd == vsm->ctrl->fd)
{
- rx_bytes = vcl_test_read (conn->fd, conn->buf, conn->buf_size,
- &conn->stats);
- rx_cfg = (vcl_test_cfg_t *) conn->buf;
+ rx_bytes = vcl_test_read (conn, conn->rxbuf, conn->rxbuf_size);
+ rx_cfg = (vcl_test_cfg_t *) conn->rxbuf;
if (rx_cfg->magic == VCL_TEST_CFG_CTRL_MAGIC)
{
vts_handle_ctrl_cfg (wrk, rx_cfg, conn, rx_bytes);
@@ -754,7 +711,7 @@ vts_worker_loop (void *arg)
goto done;
}
}
- else if (isascii (conn->buf[0]))
+ else if (isascii (conn->rxbuf[0]))
{
vts_server_echo (conn, rx_bytes);
}