20 #include <sys/types.h> 21 #include <sys/socket.h> 24 #include <arpa/inet.h> 33 struct sockaddr_storage server_addr;
50 int rx_bytes, tx_bytes;
58 stinf (
"(fd %d): Sending config sent to server.\n", socket->
fd);
64 stabrt (
"(fd %d): write test cfg failed (%d)!", socket->
fd, tx_bytes);
72 stabrt (
"(fd %d): Bad server reply cfg -- aborting!\n", socket->
fd);
76 stabrt (
"(fd %d): Invalid config received from server!\n", socket->
fd);
80 stinf (
"(fd %d): Got config back from server.", socket->
fd);
93 struct sockaddr_un serveraddr;
96 struct timeval timeout;
100 fd = socket (AF_UNIX, SOCK_STREAM, 0);
104 memset (&serveraddr, 0,
sizeof (serveraddr));
105 serveraddr.sun_family = AF_UNIX;
107 sizeof (serveraddr.sun_path));
108 rv = connect (fd, (
struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr));
115 timeout.tv_usec = 250000;
116 select (0, NULL, NULL, NULL, &timeout);
117 rv = write (fd, buffer, nbytes);
122 stabrt (
"write(fd %d, \"%s\", %lu) returned %d!", fd, buffer, nbytes, rv);
124 stinf (
"(AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
125 memset (buffer, 0,
sizeof (buffer));
126 rv = read (fd, buffer, nbytes);
131 stabrt (
"read(fd %d, %p, %lu) returned %d!\n", fd, buffer, nbytes, rv);
135 stinf (
"(AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
139 stabrt (
"(AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
150 int rx_bytes, tx_bytes, nbytes;
154 fd_set wr_fdset, rd_fdset;
155 fd_set _wfdset, *wfdset = &_wfdset;
156 fd_set _rfdset, *rfdset = &_rfdset;
160 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
171 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
173 FD_SET (tsock->
fd, &wr_fdset);
174 FD_SET (tsock->
fd, &rd_fdset);
175 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
179 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
185 struct timeval timeout;
188 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
203 if (FD_ISSET (tsock->
fd, wfdset) &&
207 nbytes, &tsock->
stats,
210 stabrt (
"sock_test_write(%d) failed -- aborting test!",
213 stinf (
"(fd %d): TX (%d bytes) - '%s'", tsock->
fd, tx_bytes,
217 if ((FD_ISSET (tsock->
fd, rfdset)) &&
221 nbytes, &tsock->
stats);
224 stinf (
"(fd %d): RX (%d bytes)\n", tsock->
fd, rx_bytes);
227 stinf (
"bytes read (%lu) != bytes written (%lu)!\n",
234 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
239 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
252 snprintf (buf,
sizeof (buf),
"CLIENT (fd %d) RESULTS", tsock->
fd);
270 stinf (
" ctrl socket info\n" 274 " rxbuf size: %u (0x%08x)\n" 276 " txbuf size: %u (0x%08x)\n" 278 ctrl->
fd, (uint32_t) ctrl->
fd,
291 int tx_bytes, rv, nfds = 0;;
293 fd_set wr_fdset, rd_fdset;
294 fd_set _wfdset, *wfdset = &_wfdset;
301 "CLIENT (fd %d): %s-directional Stream Test!\n\n" 302 "CLIENT (fd %d): Sending config to server on ctrl socket...\n",
306 stabrt (
"test cfg sync failed -- aborting!");
310 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
316 stinf (
"(fd %d): Sending config to server on test socket %d...\n",
322 tsock->
txbuf[i] = i & 0xff;
324 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
325 FD_SET (tsock->
fd, &wr_fdset);
326 FD_SET (tsock->
fd, &rd_fdset);
327 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
331 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
337 struct timeval timeout;
340 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
356 FD_ISSET (tsock->
fd, rfdset) &&
360 (uint8_t *) tsock->
rxbuf,
364 if (FD_ISSET (tsock->
fd, wfdset) &&
371 stabrt (
"sock_test_write(%d) failed -- aborting test!",
380 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
385 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
387 stinf (
"(fd %d): Sending config to server on ctrl socket...\n", ctrl->
fd);
390 stabrt (
"test cfg sync failed -- aborting!");
400 snprintf (buf,
sizeof (buf),
"CLIENT (fd %d) RESULTS", tsock->
fd);
416 stinf (
" ctrl socket info\n" 420 " rxbuf size: %u (0x%08x)\n" 422 " txbuf size: %u (0x%08x)\n" 424 ctrl->
fd, (uint32_t) ctrl->
fd,
431 stabrt (
"post-test cfg sync failed!");
433 stinf (
"(fd %d): %s-directional Stream Test Complete!\n" 446 stinf (
"af_unix_echo_tx %d, af_unix_echo_rx %d\n",
456 stinf (
"\(fd %d): Sending exit cfg to server...\n", tsock->
fd);
467 stinf (
"\n(fd %d): Sending exit cfg to server...\n", ctrl->
fd);
473 stinf (
"\nCLIENT: So long and thanks for all the fish!\n\n");
485 if (num_test_sockets < 1)
491 if (num_test_sockets < scm->num_test_sockets)
519 SOCK_DGRAM : SOCK_STREAM, 0);
524 rv = connect (tsock->
fd, (
struct sockaddr *) &scm->
server_addr,
530 if (fcntl (tsock->
fd, F_SETFL, O_NONBLOCK) < 0)
537 stinf (
"(fd %d): Test socket %d connected", tsock->
fd, i);
552 uint64_t txbuf_size = strtoull ((
const char *) p, NULL, 10);
563 stabrt (
"Invalid txbuf size (%lu) < minimum buf size (%u)!",
573 uint32_t num_writes = strtoul ((
const char *) p, NULL, 10);
582 stabrt (
"Invalid num writes: %u", num_writes);
591 uint32_t num_test_sockets = strtoul ((
const char *) p, NULL, 10);
593 if ((num_test_sockets > 0) &&
602 stabrt (
"Invalid num test sockets: %u, (%d max)\n", num_test_sockets,
612 uint64_t rxbuf_size = strtoull ((
const char *) p, NULL, 10);
622 stabrt (
"Invalid rxbuf size (%lu) < minimum buf size (%u)!",
692 stinf (
"sock_test_client [OPTIONS] <ipaddr> <port>\n" 694 " -h Print this message and exit.\n" 696 " -u Use UDP transport layer\n" 697 " -c Print test config before test.\n" 698 " -w <dir> Write test results to <dir>.\n" 699 " -X Exit after running test.\n" 700 " -E Run Echo test.\n" 701 " -N <num-writes> Test Cfg: number of writes.\n" 702 " -R <rxbuf-size> Test Cfg: rx buffer size.\n" 703 " -T <txbuf-size> Test Cfg: tx buffer size.\n" 704 " -U Run Uni-directional test.\n" 705 " -B Run Bi-directional test.\n" 706 " -V Verbose mode.\n");
722 while ((c = getopt (argc, argv,
"chn:w:XE:I:N:R:T:UBV6D")) != -1)
733 stinf (
"ERROR: Invalid value for option -%c!", c);
739 stinf (
"ERROR: Invalid number of " 740 "sockets (%d) specified for option -%c!\n" 741 " Valid range is 1 - %d\n",
748 stinf (
"Writing test results to files is TBD.\n");
758 stinf (
"ERROR: Option -%c value larger than txbuf size (%d)!",
770 stinf (
"ERROR: Invalid value for option -%c!\n", c);
775 stinf (
"ERROR: value greater than max number test sockets (%d)!",
785 stinf (
"ERROR: Invalid value for option -%c!", c);
795 stinf (
"ERROR: Invalid value for option -%c!", c);
802 (uint8_t **) & ctrl->
rxbuf,
807 stinf (
"ERROR: rxbuf size (%lu) less than minumum (%u)\n",
818 stinf (
"ERROR: Invalid value for option -%c!", c);
825 (uint8_t **) & ctrl->
txbuf,
832 stinf (
"ERROR: txbuf size (%lu) less than minumum (%u)!",
867 stinf (
"ERROR: Option -%c requires an argument.\n", optopt);
871 if (isprint (optopt))
872 stinf (
"ERROR: Unknown option `-%c'.\n", optopt);
874 stinf (
"ERROR: Unknown option character `\\x%x'.\n", optopt);
882 if (argc < (optind + 2))
884 stinf (
"ERROR: Insufficient number of arguments!\n");
897 struct sockaddr_in6 *server_addr =
900 server_addr->sin6_family = AF_INET6;
901 inet_pton (AF_INET6, argv[optind++], &(server_addr->sin6_addr));
902 server_addr->sin6_port = htons (atoi (argv[optind]));
906 struct sockaddr_in *server_addr =
909 server_addr->sin_family = AF_INET;
910 inet_pton (AF_INET, argv[optind++], &(server_addr->sin_addr));
911 server_addr->sin_port = htons (atoi (argv[optind]));
916 stinf (
"\nConnecting to server...\n");
918 rv = connect (ctrl->
fd, (
struct sockaddr *) &scm->
server_addr,
925 stinf (
"(fd %d): Control socket connected.\n", ctrl->
fd);
986 stinf (
"\nType some characters and hit <return>\n" 991 if (strlen (ctrl->
txbuf) == 1)
993 stinf (
"\nNothing to send! Please try again...\n");
static int sock_test_read(int fd, uint8_t *buf, uint32_t nbytes, vcl_test_stats_t *stats)
vcl_test_session_t ctrl_socket
#define VCL_TEST_TOKEN_RXBUF_SIZE
static void sock_client_echo_af_unix(sock_client_main_t *scm)
static void dump_help(void)
struct sockaddr_storage server_addr
uint32_t num_test_sessions
int main(int argc, char **argv)
#define VCL_TEST_CFG_BUF_SIZE_MIN
uint32_t server_addr_size
static vcl_test_t parse_input()
#define VCL_TEST_TOKEN_NUM_WRITES
#define VCL_TEST_TOKEN_SHOW_CFG
#define SOCK_TEST_BANNER_STRING
#define SOCK_TEST_AF_UNIX_FILENAME
static void vcl_test_stats_dump(char *header, vcl_test_stats_t *stats, uint8_t show_rx, uint8_t show_tx, uint8_t verbose)
static void exit_client(void)
static int sock_test_write(int fd, uint8_t *buf, uint32_t nbytes, vcl_test_stats_t *stats, uint32_t verbose)
static int sock_test_connect_test_sockets(uint32_t num_test_sockets)
#define VCL_TEST_SEPARATOR_STRING
static void vcl_test_session_buf_alloc(vcl_test_session_t *socket)
static void vcl_test_cfg_dump(vcl_test_cfg_t *cfg, uint8_t is_client)
static void stream_test_client(vcl_test_t test)
static void cfg_verbose_toggle(void)
#define VCL_TEST_CFG_CTRL_MAGIC
#define VCL_TEST_TOKEN_RUN_BI
static void echo_test_client(void)
sll srl srl sll sra u16x4 i
static void vcl_test_cfg_init(vcl_test_cfg_t *cfg)
uint32_t num_test_sockets
#define VCL_TEST_TOKEN_TXBUF_SIZE
#define VCL_TEST_TOKEN_VERBOSE
static void cfg_rxbuf_size_set(void)
static void cfg_num_writes_set(void)
#define VCL_TEST_TOKEN_HELP
static void cfg_txbuf_size_set(void)
static void vcl_test_buf_alloc(vcl_test_cfg_t *cfg, uint8_t is_rxbuf, uint8_t **buf, uint32_t *bufsize)
#define SOCK_TEST_MIXED_EPOLL_DATA
#define stabrt(_fmt, _args...)
vcl_test_session_t * test_socket
void * realloc(void *p, size_t size)
sock_client_main_t sock_client_main
#define stinf(_fmt, _args...)
#define VCL_TEST_TOKEN_RUN_UNI
static void vcl_test_stats_accumulate(vcl_test_stats_t *accum, vcl_test_stats_t *incr)
void print_usage_and_exit(void)
static void cfg_num_test_sockets_set(void)
static int sock_test_cfg_sync(vcl_test_session_t *socket)
#define VCL_TEST_TOKEN_NUM_TEST_SESS
#define VCL_TEST_TOKEN_EXIT
static int vcl_test_cfg_verify(vcl_test_cfg_t *cfg, vcl_test_cfg_t *valid_cfg)
#define VCL_TEST_CFG_MAX_TEST_SESS