diff options
author | Florin Coras <fcoras@cisco.com> | 2020-04-29 01:11:35 +0000 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2020-04-29 16:39:16 +0000 |
commit | a3108e65f396fa556e75dfe45b04a0bc3b6ec725 (patch) | |
tree | 12840d6a275410ec2454021f7d815f69f68958a6 /src/plugins/hs_apps/vcl | |
parent | 3a76dc3f4f32b8af6bd4bb2486008b6ba73a848f (diff) |
hsa: cleanup ifdefs in sock tests
Type: refactor
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I1f03d80c4ee2a555dc6baa262d6df4521c1ae818
Diffstat (limited to 'src/plugins/hs_apps/vcl')
-rw-r--r-- | src/plugins/hs_apps/vcl/sock_test_client.c | 362 | ||||
-rw-r--r-- | src/plugins/hs_apps/vcl/sock_test_server.c | 286 | ||||
-rw-r--r-- | src/plugins/hs_apps/vcl/vcl_test.h | 26 | ||||
-rw-r--r-- | src/plugins/hs_apps/vcl/vcl_test_client.c | 26 |
4 files changed, 168 insertions, 532 deletions
diff --git a/src/plugins/hs_apps/vcl/sock_test_client.c b/src/plugins/hs_apps/vcl/sock_test_client.c index fb59378e008..7f5b1114686 100644 --- a/src/plugins/hs_apps/vcl/sock_test_client.c +++ b/src/plugins/hs_apps/vcl/sock_test_client.c @@ -24,18 +24,12 @@ #include <arpa/inet.h> #include <hs_apps/vcl/sock_test.h> #include <fcntl.h> -#ifndef VCL_TEST #include <sys/un.h> -#endif typedef struct { -#ifdef VCL_TEST - vppcom_endpt_t server_endpt; -#else int af_unix_echo_tx; int af_unix_echo_rx; -#endif struct sockaddr_storage server_addr; uint32_t server_addr_size; uint32_t cfg_seq_num; @@ -45,13 +39,12 @@ typedef struct uint8_t dump_cfg; } sock_client_main_t; -sock_client_main_t vcl_client_main; - +sock_client_main_t sock_client_main; static int sock_test_cfg_sync (vcl_test_session_t * socket) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; 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; @@ -116,9 +109,99 @@ sock_test_cfg_sync (vcl_test_session_t * socket) } static void +sock_client_echo_af_unix (sock_client_main_t * scm) +{ + int fd, errno_val; + struct sockaddr_un serveraddr; + uint8_t buffer[256]; + size_t nbytes = strlen (SOCK_TEST_MIXED_EPOLL_DATA) + 1; + struct timeval timeout; + int rv; + + /* Open AF_UNIX socket and send an echo to test mixed epoll on server. + */ + fd = socket (AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) + { + errno_val = errno; + perror ("ERROR in echo_test_client(): socket(AF_UNIX) failed"); + fprintf (stderr, + "CLIENT: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed " + "(errno = %d)!\n", errno_val); + goto out; + } + memset (&serveraddr, 0, sizeof (serveraddr)); + serveraddr.sun_family = AF_UNIX; + strncpy (serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME, + sizeof (serveraddr.sun_path)); + rv = connect (fd, (struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr)); + if (rv < 0) + { + errno_val = errno; + perror ("ERROR in echo_test_client(): connect() failed"); + fprintf (stderr, "CLIENT: ERROR: connect(fd %d, \"%s\", %lu) " + "failed (errno = %d)!\n", fd, SOCK_TEST_AF_UNIX_FILENAME, + SUN_LEN (&serveraddr), errno_val); + goto done; + } + + scm->af_unix_echo_tx++; + strncpy ((char *) buffer, SOCK_TEST_MIXED_EPOLL_DATA, sizeof (buffer)); + timeout.tv_sec = 0; + timeout.tv_usec = 250000; + select (0, NULL, NULL, NULL, &timeout); /* delay .25 secs */ + rv = write (fd, buffer, nbytes); + if (rv < 0) + { + errno_val = errno; + perror ("ERROR in echo_test_client(): write() failed"); + fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) " + "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val); + goto done; + } + else if (rv < nbytes) + { + fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) " + "returned %d!\n", fd, buffer, nbytes, rv); + goto done; + } + + printf ("CLIENT (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer); + memset (buffer, 0, sizeof (buffer)); + rv = read (fd, buffer, nbytes); + if (rv < 0) + { + errno_val = errno; + perror ("ERROR in echo_test_client(): read() failed"); + fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) " + "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val); + goto done; + } + else if (rv < nbytes) + { + fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) " + "returned %d!\n", fd, buffer, nbytes, rv); + goto done; + } + + if (!strncmp (SOCK_TEST_MIXED_EPOLL_DATA, (const char *) buffer, nbytes)) + { + printf ("CLIENT (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer); + scm->af_unix_echo_rx++; + } + else + printf ("CLIENT (AF_UNIX): ERROR: RX (%d bytes) - '%s'\n", rv, buffer); + +done: + close (fd); +out: + ; +} + +static void echo_test_client () { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; vcl_test_session_t *ctrl = &scm->ctrl_socket; vcl_test_session_t *tsock; int rx_bytes, tx_bytes, nbytes; @@ -156,18 +239,11 @@ echo_test_client () _wfdset = wr_fdset; _rfdset = rd_fdset; -#ifdef VCL_TEST - rv = - vppcom_select (nfds, (unsigned long *) rfdset, - (unsigned long *) wfdset, NULL, 0); -#else - { - struct timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - rv = select (nfds, rfdset, wfdset, NULL, &timeout); - } -#endif + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 0; + rv = select (nfds, rfdset, wfdset, NULL, &timeout); + if (rv < 0) { perror ("select()"); @@ -230,94 +306,7 @@ echo_test_client () } clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop); -#ifndef VCL_TEST - { - int fd, errno_val; - struct sockaddr_un serveraddr; - uint8_t buffer[256]; - size_t nbytes = strlen (SOCK_TEST_MIXED_EPOLL_DATA) + 1; - struct timeval timeout; - - /* Open AF_UNIX socket and send an echo to test mixed epoll on server. - */ - fd = socket (AF_UNIX, SOCK_STREAM, 0); - if (fd < 0) - { - errno_val = errno; - perror ("ERROR in echo_test_client(): socket(AF_UNIX) failed"); - fprintf (stderr, - "CLIENT: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed " - "(errno = %d)!\n", errno_val); - goto out; - } - memset (&serveraddr, 0, sizeof (serveraddr)); - serveraddr.sun_family = AF_UNIX; - strncpy (serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME, - sizeof (serveraddr.sun_path)); - rv = connect (fd, (struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr)); - if (rv < 0) - { - errno_val = errno; - perror ("ERROR in echo_test_client(): connect() failed"); - fprintf (stderr, "CLIENT: ERROR: connect(fd %d, \"%s\", %lu) " - "failed (errno = %d)!\n", fd, SOCK_TEST_AF_UNIX_FILENAME, - SUN_LEN (&serveraddr), errno_val); - goto done; - } - - scm->af_unix_echo_tx++; - strncpy ((char *) buffer, SOCK_TEST_MIXED_EPOLL_DATA, sizeof (buffer)); - timeout.tv_sec = 0; - timeout.tv_usec = 250000; - select (0, NULL, NULL, NULL, &timeout); /* delay .25 secs */ - rv = write (fd, buffer, nbytes); - if (rv < 0) - { - errno_val = errno; - perror ("ERROR in echo_test_client(): write() failed"); - fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) " - "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val); - goto done; - } - else if (rv < nbytes) - { - fprintf (stderr, "CLIENT: ERROR: write(fd %d, \"%s\", %lu) " - "returned %d!\n", fd, buffer, nbytes, rv); - goto done; - } - - printf ("CLIENT (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer); - memset (buffer, 0, sizeof (buffer)); - rv = read (fd, buffer, nbytes); - if (rv < 0) - { - errno_val = errno; - perror ("ERROR in echo_test_client(): read() failed"); - fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) " - "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val); - goto done; - } - else if (rv < nbytes) - { - fprintf (stderr, "CLIENT: ERROR: read(fd %d, %p, %lu) " - "returned %d!\n", fd, buffer, nbytes, rv); - goto done; - } - - if (!strncmp (SOCK_TEST_MIXED_EPOLL_DATA, (const char *) buffer, nbytes)) - { - printf ("CLIENT (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer); - scm->af_unix_echo_rx++; - } - else - printf ("CLIENT (AF_UNIX): ERROR: RX (%d bytes) - '%s'\n", rv, buffer); - - done: - close (fd); - out: - ; - } -#endif + sock_client_echo_af_unix (scm); for (i = 0; i < ctrl->cfg.num_test_sessions; i++) { @@ -364,7 +353,7 @@ echo_test_client () static void stream_test_client (vcl_test_t test) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; vcl_test_session_t *ctrl = &scm->ctrl_socket; vcl_test_session_t *tsock; int tx_bytes; @@ -418,18 +407,11 @@ stream_test_client (vcl_test_t test) _wfdset = wr_fdset; _rfdset = rd_fdset; -#ifdef VCL_TEST - rv = - vppcom_select (nfds, (unsigned long *) rfdset, - (unsigned long *) wfdset, NULL, 0); -#else - { - struct timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - rv = select (nfds, rfdset, wfdset, NULL, &timeout); - } -#endif + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 0; + rv = select (nfds, rfdset, wfdset, NULL, &timeout); + if (rv < 0) { perror ("select()"); @@ -540,15 +522,13 @@ stream_test_client (vcl_test_t test) static void exit_client (void) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; 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_sessions; i++) { tsock = &scm->test_socket[i]; @@ -582,7 +562,7 @@ exit_client (void) static int sock_test_connect_test_sockets (uint32_t num_test_sockets) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; vcl_test_session_t *ctrl = &scm->ctrl_socket; vcl_test_session_t *tsock; int i, rv, errno_val; @@ -598,11 +578,7 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets) for (i = scm->num_test_sockets - 1; i >= num_test_sockets; i--) { tsock = &scm->test_socket[i]; -#ifdef VCL_TEST - vppcom_session_close (tsock->fd); -#else close (tsock->fd); -#endif free (tsock->txbuf); free (tsock->rxbuf); } @@ -629,21 +605,10 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets) for (i = scm->num_test_sockets; i < num_test_sockets; i++) { tsock = &scm->test_socket[i]; -#ifdef VCL_TEST - tsock->fd = vppcom_session_create (ctrl->cfg.transport_udp ? - VPPCOM_PROTO_UDP : - VPPCOM_PROTO_TCP, - 1 /* is_nonblocking */ ); - if (tsock->fd < 0) - { - errno = -tsock->fd; - tsock->fd = -1; - } -#else tsock->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET, ctrl->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM, 0); -#endif + if (tsock->fd < 0) { errno_val = errno; @@ -653,17 +618,9 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets) return tsock->fd; } -#ifdef VCL_TEST - rv = vppcom_session_connect (tsock->fd, &scm->server_endpt); - if (rv) - { - errno = -rv; - rv = -1; - } -#else rv = connect (tsock->fd, (struct sockaddr *) &scm->server_addr, scm->server_addr_size); -#endif + if (rv < 0) { errno_val = errno; @@ -695,35 +652,9 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets) } static void -dump_help (void) -{ -#define INDENT "\n " - - printf ("CLIENT: Test configuration commands:" - INDENT VCL_TEST_TOKEN_HELP - "\t\t\tDisplay help." - INDENT VCL_TEST_TOKEN_EXIT - "\t\t\tExit test client & server." - INDENT VCL_TEST_TOKEN_SHOW_CFG - "\t\t\tShow the current test cfg." - INDENT VCL_TEST_TOKEN_RUN_UNI - "\t\t\tRun the Uni-directional test." - INDENT VCL_TEST_TOKEN_RUN_BI - "\t\t\tRun the Bi-directional test." - INDENT VCL_TEST_TOKEN_VERBOSE - "\t\t\tToggle verbose setting." - INDENT VCL_TEST_TOKEN_RXBUF_SIZE - "<rxbuf size>\tRx buffer size (bytes)." - INDENT VCL_TEST_TOKEN_TXBUF_SIZE - "<txbuf size>\tTx buffer size (bytes)." - INDENT VCL_TEST_TOKEN_NUM_WRITES - "<# of writes>\tNumber of txbuf writes to server." "\n"); -} - -static void cfg_txbuf_size_set (void) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; 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); @@ -745,7 +676,7 @@ cfg_txbuf_size_set (void) static void cfg_num_writes_set (void) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; 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); @@ -765,7 +696,7 @@ cfg_num_writes_set (void) static void cfg_num_test_sockets_set (void) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; 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); @@ -789,7 +720,7 @@ cfg_num_test_sockets_set (void) static void cfg_rxbuf_size_set (void) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; 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); @@ -810,7 +741,7 @@ cfg_rxbuf_size_set (void) static void cfg_verbose_toggle (void) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; vcl_test_session_t *ctrl = &scm->ctrl_socket; ctrl->cfg.verbose = ctrl->cfg.verbose ? 0 : 1; @@ -821,7 +752,7 @@ cfg_verbose_toggle (void) static vcl_test_t parse_input () { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; vcl_test_session_t *ctrl = &scm->ctrl_socket; vcl_test_t rv = VCL_TEST_TYPE_NONE; @@ -896,7 +827,7 @@ print_usage_and_exit (void) int main (int argc, char **argv) { - sock_client_main_t *scm = &vcl_client_main; + sock_client_main_t *scm = &sock_client_main; vcl_test_session_t *ctrl = &scm->ctrl_socket; int c, rv, errno_val; vcl_test_t post_test = VCL_TEST_TYPE_NONE; @@ -1082,29 +1013,8 @@ main (int argc, char **argv) print_usage_and_exit (); } -#ifdef VCL_TEST - ctrl->fd = vppcom_app_create ("vcl_test_client"); - if (ctrl->fd < 0) - { - errno = -ctrl->fd; - ctrl->fd = -1; - } - else - { - ctrl->fd = vppcom_session_create (ctrl->cfg.transport_udp ? - VPPCOM_PROTO_UDP : - VPPCOM_PROTO_TCP, - 0 /* is_nonblocking */ ); - if (ctrl->fd < 0) - { - errno = -ctrl->fd; - ctrl->fd = -1; - } - } -#else ctrl->fd = socket (ctrl->cfg.address_ip6 ? AF_INET6 : AF_INET, ctrl->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM, 0); -#endif if (ctrl->fd < 0) { @@ -1135,41 +1045,13 @@ main (int argc, char **argv) server_addr->sin_port = htons (atoi (argv[optind])); } -#ifdef VCL_TEST - if (ctrl->cfg.address_ip6) - { - struct sockaddr_in6 *server_addr = - (struct sockaddr_in6 *) &scm->server_addr; - scm->server_endpt.is_ip4 = 0; - scm->server_endpt.ip = (uint8_t *) & server_addr->sin6_addr; - scm->server_endpt.port = (uint16_t) server_addr->sin6_port; - } - else - { - struct sockaddr_in *server_addr = - (struct sockaddr_in *) &scm->server_addr; - scm->server_endpt.is_ip4 = 1; - scm->server_endpt.ip = (uint8_t *) & server_addr->sin_addr; - scm->server_endpt.port = (uint16_t) server_addr->sin_port; - } -#endif - do { printf ("\nCLIENT: Connecting to server...\n"); -#ifdef VCL_TEST - rv = vppcom_session_connect (ctrl->fd, &scm->server_endpt); - if (rv) - { - errno = -rv; - rv = -1; - } -#else - rv = - connect (ctrl->fd, (struct sockaddr *) &scm->server_addr, - scm->server_addr_size); -#endif + rv = connect (ctrl->fd, (struct sockaddr *) &scm->server_addr, + scm->server_addr_size); + if (rv < 0) { errno_val = errno; @@ -1259,14 +1141,8 @@ main (int argc, char **argv) } exit_client (); -#ifdef VCL_TEST - vppcom_session_close (ctrl->fd); - vppcom_app_destroy (); - return 0; -#else close (ctrl->fd); return (scm->af_unix_echo_tx == scm->af_unix_echo_rx) ? 0 : -1; -#endif } /* diff --git a/src/plugins/hs_apps/vcl/sock_test_server.c b/src/plugins/hs_apps/vcl/sock_test_server.c index 801cd83cc83..e7add1a298d 100644 --- a/src/plugins/hs_apps/vcl/sock_test_server.c +++ b/src/plugins/hs_apps/vcl/sock_test_server.c @@ -25,25 +25,11 @@ #include <sys/stat.h> #include <fcntl.h> #include <sys/ioctl.h> - -#define SOCK_SERVER_USE_EPOLL 1 -#define VPPCOM_SESSION_ATTR_UNIT_TEST 0 - -#if SOCK_SERVER_USE_EPOLL #include <sys/epoll.h> -#if !defined(VCL_TEST) #include <sys/un.h> -#endif -#endif -#ifdef VCL_TEST -#if VPPCOM_SESSION_ATTR_UNIT_TEST -#define BUFLEN sizeof (uint64_t) * 16 -uint64_t buffer[16]; -uint32_t buflen = BUFLEN; -uint32_t *flags = (uint32_t *) buffer; -#endif -#endif +#define SOCK_SERVER_MAX_TEST_CONN 10 +#define SOCK_SERVER_MAX_EPOLL_EVENTS 10 typedef struct { @@ -53,10 +39,6 @@ typedef struct uint32_t buf_size; vcl_test_cfg_t cfg; vcl_test_stats_t stats; -#ifdef VCL_TEST - vppcom_endpt_t endpt; - uint8_t ip[16]; -#endif } sock_server_conn_t; typedef struct @@ -66,24 +48,18 @@ typedef struct uint32_t transport_udp; } sock_server_cfg_t; -#define SOCK_SERVER_MAX_TEST_CONN 10 -#define SOCK_SERVER_MAX_EPOLL_EVENTS 10 typedef struct { int listen_fd; sock_server_cfg_t cfg; -#if SOCK_SERVER_USE_EPOLL int epfd; struct epoll_event listen_ev; struct epoll_event wait_events[SOCK_SERVER_MAX_EPOLL_EVENTS]; -#if !defined (VCL_TEST) int af_unix_listen_fd; int af_unix_fd; struct epoll_event af_unix_listen_ev; struct sockaddr_un serveraddr; uint32_t af_unix_xacts; -#endif -#endif size_t num_conn; size_t conn_pool_size; sock_server_conn_t *conn_pool; @@ -95,40 +71,6 @@ typedef struct sock_server_main_t sock_server_main; -#if ! SOCK_SERVER_USE_EPOLL -static inline int -get_nfds (void) -{ - sock_server_main_t *ssm = &sock_server_main; - int i, nfds; - - for (nfds = i = 0; i < FD_SETSIZE; i++) - { - if (FD_ISSET (i, &ssm->rd_fdset) || FD_ISSET (i, &ssm->wr_fdset)) - nfds = i + 1; - } - return nfds; -} - -static inline void -conn_fdset_set (sock_server_conn_t * conn, fd_set * fdset) -{ - sock_server_main_t *ssm = &sock_server_main; - - FD_SET (conn->fd, fdset); - ssm->nfds = get_nfds (); -} - -static inline void -conn_fdset_clr (sock_server_conn_t * conn, fd_set * fdset) -{ - sock_server_main_t *ssm = &sock_server_main; - - FD_CLR (conn->fd, fdset); - ssm->nfds = get_nfds (); -} -#endif - static inline void conn_pool_expand (size_t expand_size) { @@ -172,9 +114,6 @@ conn_pool_alloc (void) { if (!ssm->conn_pool[i].is_alloc) { -#ifdef VCL_TEST - ssm->conn_pool[i].endpt.ip = ssm->conn_pool[i].ip; -#endif ssm->conn_pool[i].is_alloc = 1; return (&ssm->conn_pool[i]); } @@ -186,12 +125,6 @@ conn_pool_alloc (void) static inline void conn_pool_free (sock_server_conn_t * conn) { -#if ! SOCK_SERVER_USE_EPOLL - sock_server_main_t *ssm = &sock_server_main; - - conn_fdset_clr (conn, &ssm->rd_fdset); - conn_fdset_clr (conn, &ssm->wr_fdset); -#endif conn->fd = 0; conn->is_alloc = 0; } @@ -302,7 +235,6 @@ stream_test_server (sock_server_conn_t * conn, int rx_bytes) } } -#if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST) static inline void af_unix_echo (void) { @@ -369,8 +301,6 @@ done: close (af_unix_client_fd); } -#endif - static inline void new_client (void) { @@ -388,11 +318,7 @@ new_client (void) return; } -#ifdef VCL_TEST - client_fd = vppcom_session_accept (ssm->listen_fd, &conn->endpt, 0); - if (client_fd < 0) - errno = -client_fd; -#elif HAVE_ACCEPT4 +#if HAVE_ACCEPT4 client_fd = accept4 (ssm->listen_fd, (struct sockaddr *) NULL, NULL, NULL); #else client_fd = accept (ssm->listen_fd, (struct sockaddr *) NULL, NULL); @@ -412,35 +338,23 @@ new_client (void) conn->fd = client_fd; -#if ! SOCK_SERVER_USE_EPOLL - conn_fdset_set (conn, &ssm->rd_fdset); - ssm->nfds++; -#else - { - struct epoll_event ev; - int rv; - - ev.events = EPOLLIN; - ev.data.u64 = conn - ssm->conn_pool; -#ifdef VCL_TEST - rv = vppcom_epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev); - if (rv) - errno = -rv; -#else - rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev); -#endif - if (rv < 0) - { - int errno_val; - errno_val = errno; - perror ("ERROR in new_client()"); - fprintf (stderr, "SERVER: ERROR: epoll_ctl failed (errno = %d)!\n", - errno_val); - } - else - ssm->nfds++; - } -#endif + struct epoll_event ev; + int rv; + + ev.events = EPOLLIN; + ev.data.u64 = conn - ssm->conn_pool; + rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev); + + if (rv < 0) + { + int errno_val; + errno_val = errno; + perror ("ERROR in new_client()"); + fprintf (stderr, "SERVER: ERROR: epoll_ctl failed (errno = %d)!\n", + errno_val); + } + else + ssm->nfds++; } void @@ -469,17 +383,7 @@ main (int argc, char **argv) int errno_val; int c, v, i; uint16_t port = VCL_TEST_SERVER_PORT; -#if ! SOCK_SERVER_USE_EPOLL - fd_set _rfdset, *rfdset = &_rfdset; -#endif -#ifdef VCL_TEST - vppcom_endpt_t endpt; -#else uint32_t servaddr_size; -#if ! SOCK_SERVER_USE_EPOLL - fd_set _wfdset, *wfdset = &_wfdset; -#endif -#endif opterr = 0; while ((c = getopt (argc, argv, "6D")) != -1) @@ -526,25 +430,9 @@ main (int argc, char **argv) conn_pool_expand (SOCK_SERVER_MAX_TEST_CONN + 1); -#ifdef VCL_TEST - rv = vppcom_app_create ("vcl_test_server"); - if (rv) - { - errno = -rv; - ssm->listen_fd = -1; - } - else - { - ssm->listen_fd = vppcom_session_create (ssm->cfg.transport_udp ? - VPPCOM_PROTO_UDP : - VPPCOM_PROTO_TCP, - 0 /* is_nonblocking */ ); - } -#else ssm->listen_fd = socket (ssm->cfg.address_ip6 ? AF_INET6 : AF_INET, ssm->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM, 0); -#if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST) unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME); ssm->af_unix_listen_fd = socket (AF_UNIX, SOCK_STREAM, 0); if (ssm->af_unix_listen_fd < 0) @@ -588,8 +476,7 @@ main (int argc, char **argv) unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME); return rv; } -#endif /* SOCK_SERVER_USE_EPOLL */ -#endif + if (ssm->listen_fd < 0) { errno_val = errno; @@ -604,9 +491,7 @@ main (int argc, char **argv) if (ssm->cfg.address_ip6) { struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) &servaddr; -#ifndef VCL_TEST servaddr_size = sizeof (*server_addr); -#endif server_addr->sin6_family = AF_INET6; server_addr->sin6_addr = in6addr_any; server_addr->sin6_port = htons (port); @@ -614,43 +499,17 @@ main (int argc, char **argv) else { struct sockaddr_in *server_addr = (struct sockaddr_in *) &servaddr; -#ifndef VCL_TEST servaddr_size = sizeof (*server_addr); -#endif server_addr->sin_family = AF_INET; server_addr->sin_addr.s_addr = htonl (INADDR_ANY); server_addr->sin_port = htons (port); } -#ifdef VCL_TEST - if (ssm->cfg.address_ip6) - { - struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) &servaddr; - endpt.is_ip4 = 0; - endpt.ip = (uint8_t *) & server_addr->sin6_addr; - endpt.port = (uint16_t) server_addr->sin6_port; - } - else - { - struct sockaddr_in *server_addr = (struct sockaddr_in *) &servaddr; - endpt.is_ip4 = 1; - endpt.ip = (uint8_t *) & server_addr->sin_addr; - endpt.port = (uint16_t) server_addr->sin_port; - } - - rv = vppcom_session_bind (ssm->listen_fd, &endpt); - if (rv) - { - errno = -rv; - rv = -1; - } -#else rv = bind (ssm->listen_fd, (struct sockaddr *) &servaddr, servaddr_size); -#endif if (rv < 0) { errno_val = errno; - perror ("ERROR in main()"); + perror ("ERROR bind returned"); fprintf (stderr, "SERVER: ERROR: bind failed (errno = %d)!\n", errno_val); return rv; @@ -658,22 +517,13 @@ main (int argc, char **argv) if (fcntl (ssm->listen_fd, F_SETFL, O_NONBLOCK) < 0) { errno_val = errno; - perror ("ERROR in main()"); + perror ("ERROR fcntl returned"); fprintf (stderr, "SERVER: ERROR: fcntl failed (errno = %d)!\n", errno_val); return rv; } -#ifdef VCL_TEST - rv = vppcom_session_listen (ssm->listen_fd, 10); - if (rv) - { - errno = -rv; - rv = -1; - } -#else rv = listen (ssm->listen_fd, 10); -#endif if (rv < 0) { errno_val = errno; @@ -683,22 +533,7 @@ main (int argc, char **argv) return rv; } -#if ! SOCK_SERVER_USE_EPOLL - - FD_ZERO (&ssm->wr_fdset); - FD_ZERO (&ssm->rd_fdset); - - FD_SET (ssm->listen_fd, &ssm->rd_fdset); - ssm->nfds = ssm->listen_fd + 1; - -#else -#ifdef VCL_TEST - ssm->epfd = vppcom_epoll_create (); - if (ssm->epfd < 0) - errno = -ssm->epfd; -#else ssm->epfd = epoll_create (1); -#endif if (ssm->epfd < 0) { errno_val = errno; @@ -710,12 +545,6 @@ main (int argc, char **argv) ssm->listen_ev.events = EPOLLIN; ssm->listen_ev.data.u32 = ~0; -#ifdef VCL_TEST - rv = vppcom_epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->listen_fd, - &ssm->listen_ev); - if (rv < 0) - errno = -rv; -#else ssm->af_unix_listen_ev.events = EPOLLIN; ssm->af_unix_listen_ev.data.u32 = SOCK_TEST_AF_UNIX_ACCEPT_DATA; rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->af_unix_listen_fd, @@ -734,7 +563,6 @@ main (int argc, char **argv) } rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->listen_fd, &ssm->listen_ev); -#endif if (rv < 0) { errno_val = errno; @@ -743,55 +571,14 @@ main (int argc, char **argv) "(errno = %d)!\n", errno_val); return rv; } -#endif printf ("\nSERVER: Waiting for a client to connect on port %d...\n", port); while (1) { -#if ! SOCK_SERVER_USE_EPOLL - _rfdset = ssm->rd_fdset; - -#ifdef VCL_TEST - rv = vppcom_select (ssm->nfds, (unsigned long *) rfdset, NULL, NULL, 0); -#else - { - struct timeval timeout; - timeout = ssm->timeout; - _wfdset = ssm->wr_fdset; - rv = select (ssm->nfds, rfdset, wfdset, NULL, &timeout); - } -#endif - if (rv < 0) - { - perror ("select()"); - fprintf (stderr, "\nSERVER: ERROR: select() failed -- aborting!\n"); - main_rv = -1; - goto done; - } - else if (rv == 0) - continue; - - if (FD_ISSET (ssm->listen_fd, rfdset)) - new_client (); - - for (i = 0; i < ssm->conn_pool_size; i++) - { - if (!ssm->conn_pool[i].is_alloc) - continue; - - conn = &ssm->conn_pool[i]; -#else int num_ev; -#ifdef VCL_TEST - num_ev = vppcom_epoll_wait (ssm->epfd, ssm->wait_events, - SOCK_SERVER_MAX_EPOLL_EVENTS, 60.0); - if (num_ev < 0) - errno = -num_ev; -#else num_ev = epoll_wait (ssm->epfd, ssm->wait_events, SOCK_SERVER_MAX_EPOLL_EVENTS, 60000); -#endif if (num_ev < 0) { perror ("epoll_wait()"); @@ -810,11 +597,7 @@ main (int argc, char **argv) conn = &ssm->conn_pool[ssm->wait_events[i].data.u32]; if (ssm->wait_events[i].events & (EPOLLHUP | EPOLLRDHUP)) { -#ifdef VCL_TEST - vppcom_session_close (conn->fd); -#else close (conn->fd); -#endif continue; } if (ssm->wait_events[i].data.u32 == ~0) @@ -822,22 +605,15 @@ main (int argc, char **argv) new_client (); continue; } -#if !defined (VCL_TEST) else if (ssm->wait_events[i].data.u32 == SOCK_TEST_AF_UNIX_ACCEPT_DATA) { af_unix_echo (); continue; } -#endif -#endif client_fd = conn->fd; -#if ! SOCK_SERVER_USE_EPOLL - if (FD_ISSET (client_fd, rfdset)) -#else if (EPOLLIN & ssm->wait_events[i].events) -#endif { read_again: rx_bytes = sock_test_read (client_fd, conn->buf, @@ -888,19 +664,11 @@ main (int argc, char **argv) case VCL_TEST_TYPE_EXIT: printf ("SERVER: Have a great day, " "connection %d!\n", client_fd); -#ifdef VCL_TEST - vppcom_session_close (client_fd); -#else close (client_fd); -#endif conn_pool_free (conn); printf ("SERVER: Closed client fd %d\n", client_fd); -#if ! SOCK_SERVER_USE_EPOLL - if (ssm->nfds == (ssm->listen_fd + 1)) -#else ssm->nfds--; if (!ssm->nfds) -#endif { printf ("SERVER: All client connections " "closed.\n\nSERVER: " @@ -990,18 +758,10 @@ main (int argc, char **argv) } done: -#ifdef VCL_TEST - vppcom_session_close (ssm->listen_fd); - vppcom_app_destroy (); -#else close (ssm->listen_fd); - -#if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST) close (ssm->af_unix_listen_fd); unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME); -#endif /* SOCK_SERVER_USE_EPOLL */ -#endif if (ssm->conn_pool) free (ssm->conn_pool); diff --git a/src/plugins/hs_apps/vcl/vcl_test.h b/src/plugins/hs_apps/vcl/vcl_test.h index 7586e29749a..c6b9230e6c9 100644 --- a/src/plugins/hs_apps/vcl/vcl_test.h +++ b/src/plugins/hs_apps/vcl/vcl_test.h @@ -518,6 +518,32 @@ vcl_test_write (int fd, uint8_t * buf, uint32_t nbytes, return (tx_bytes); } +static inline void +dump_help (void) +{ +#define INDENT "\n " + + printf ("CLIENT: Test configuration commands:" + INDENT VCL_TEST_TOKEN_HELP + "\t\t\tDisplay help." + INDENT VCL_TEST_TOKEN_EXIT + "\t\t\tExit test client & server." + INDENT VCL_TEST_TOKEN_SHOW_CFG + "\t\t\tShow the current test cfg." + INDENT VCL_TEST_TOKEN_RUN_UNI + "\t\t\tRun the Uni-directional test." + INDENT VCL_TEST_TOKEN_RUN_BI + "\t\t\tRun the Bi-directional test." + INDENT VCL_TEST_TOKEN_VERBOSE + "\t\t\tToggle verbose setting." + INDENT VCL_TEST_TOKEN_RXBUF_SIZE + "<rxbuf size>\tRx buffer size (bytes)." + INDENT VCL_TEST_TOKEN_TXBUF_SIZE + "<txbuf size>\tTx buffer size (bytes)." + INDENT VCL_TEST_TOKEN_NUM_WRITES + "<# of writes>\tNumber of txbuf writes to server." "\n"); +} + #endif /* __vcl_test_h__ */ /* diff --git a/src/plugins/hs_apps/vcl/vcl_test_client.c b/src/plugins/hs_apps/vcl/vcl_test_client.c index 236cbfff913..51544a7a445 100644 --- a/src/plugins/hs_apps/vcl/vcl_test_client.c +++ b/src/plugins/hs_apps/vcl/vcl_test_client.c @@ -642,32 +642,6 @@ vtc_stream_client (vcl_test_client_main_t * vcm) } static void -dump_help (void) -{ -#define INDENT "\n " - - printf ("CLIENT: Test configuration commands:" - INDENT VCL_TEST_TOKEN_HELP - "\t\t\tDisplay help." - INDENT VCL_TEST_TOKEN_EXIT - "\t\t\tExit test client & server." - INDENT VCL_TEST_TOKEN_SHOW_CFG - "\t\t\tShow the current test cfg." - INDENT VCL_TEST_TOKEN_RUN_UNI - "\t\t\tRun the Uni-directional test." - INDENT VCL_TEST_TOKEN_RUN_BI - "\t\t\tRun the Bi-directional test." - INDENT VCL_TEST_TOKEN_VERBOSE - "\t\t\tToggle verbose setting." - INDENT VCL_TEST_TOKEN_RXBUF_SIZE - "<rxbuf size>\tRx buffer size (bytes)." - INDENT VCL_TEST_TOKEN_TXBUF_SIZE - "<txbuf size>\tTx buffer size (bytes)." - INDENT VCL_TEST_TOKEN_NUM_WRITES - "<# of writes>\tNumber of txbuf writes to server." "\n"); -} - -static void cfg_txbuf_size_set (void) { vcl_test_client_main_t *vcm = &vcl_client_main; |