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 printf (
"CLIENT (fd %d): Sending config sent to server.\n", socket->
fd);
65 fprintf (stderr,
"CLIENT (fd %d): ERROR: write test cfg failed (%d)!\n",
66 socket->
fd, tx_bytes);
77 fprintf (stderr,
"CLIENT (fd %d): ERROR: Bad server reply cfg " 78 "-- aborting!\n", socket->
fd);
84 fprintf (stderr,
"CLIENT (fd %d): ERROR: Invalid config received " 85 "from server!\n", socket->
fd);
88 fprintf (stderr,
"\tRx bytes %d != cfg size %lu\n",
94 fprintf (stderr,
"CLIENT (fd %d): Valid config sent to server.\n",
102 printf (
"CLIENT (fd %d): Got config back from server.\n", socket->
fd);
115 struct sockaddr_un serveraddr;
118 struct timeval timeout;
123 fd = socket (AF_UNIX, SOCK_STREAM, 0);
127 perror (
"ERROR in echo_test_client(): socket(AF_UNIX) failed");
129 "CLIENT: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed " 130 "(errno = %d)!\n", errno_val);
133 memset (&serveraddr, 0,
sizeof (serveraddr));
134 serveraddr.sun_family = AF_UNIX;
136 sizeof (serveraddr.sun_path));
137 rv = connect (fd, (
struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr));
141 perror (
"ERROR in echo_test_client(): connect() failed");
142 fprintf (stderr,
"CLIENT: ERROR: connect(fd %d, \"%s\", %lu) " 144 SUN_LEN (&serveraddr), errno_val);
151 timeout.tv_usec = 250000;
152 select (0, NULL, NULL, NULL, &timeout);
153 rv = write (fd, buffer, nbytes);
157 perror (
"ERROR in echo_test_client(): write() failed");
158 fprintf (stderr,
"CLIENT: ERROR: write(fd %d, \"%s\", %lu) " 159 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
162 else if (rv < nbytes)
164 fprintf (stderr,
"CLIENT: ERROR: write(fd %d, \"%s\", %lu) " 165 "returned %d!\n", fd, buffer, nbytes, rv);
169 printf (
"CLIENT (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
170 memset (buffer, 0,
sizeof (buffer));
171 rv = read (fd, buffer, nbytes);
175 perror (
"ERROR in echo_test_client(): read() failed");
176 fprintf (stderr,
"CLIENT: ERROR: read(fd %d, %p, %lu) " 177 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
180 else if (rv < nbytes)
182 fprintf (stderr,
"CLIENT: ERROR: read(fd %d, %p, %lu) " 183 "returned %d!\n", fd, buffer, nbytes, rv);
189 printf (
"CLIENT (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
193 printf (
"CLIENT (AF_UNIX): ERROR: RX (%d bytes) - '%s'\n", rv, buffer);
207 int rx_bytes, tx_bytes, nbytes;
211 fd_set wr_fdset, rd_fdset;
212 fd_set _wfdset, *wfdset = &_wfdset;
213 fd_set _rfdset, *rfdset = &_rfdset;
217 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
228 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
230 FD_SET (tsock->
fd, &wr_fdset);
231 FD_SET (tsock->
fd, &rd_fdset);
232 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
236 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
242 struct timeval timeout;
245 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
250 fprintf (stderr,
"\nCLIENT: ERROR: select() failed -- " 264 if (FD_ISSET (tsock->
fd, wfdset) &&
273 fprintf (stderr,
"\nCLIENT: ERROR: sock_test_write(%d) " 274 "failed -- aborting test!\n", tsock->
fd);
278 printf (
"CLIENT (fd %d): TX (%d bytes) - '%s'\n",
279 tsock->
fd, tx_bytes, tsock->
txbuf);
282 if ((FD_ISSET (tsock->
fd, rfdset)) &&
287 nbytes, &tsock->
stats);
290 printf (
"CLIENT (fd %d): RX (%d bytes)\n", tsock->
fd,
294 printf (
"CLIENT: WARNING: bytes read (%lu) " 295 "!= bytes written (%lu)!\n",
302 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
307 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
320 snprintf (buf,
sizeof (buf),
"CLIENT (fd %d) RESULTS", tsock->
fd);
338 printf (
" ctrl socket info\n" 342 " rxbuf size: %u (0x%08x)\n" 344 " txbuf size: %u (0x%08x)\n" 346 ctrl->
fd, (uint32_t) ctrl->
fd,
363 fd_set wr_fdset, rd_fdset;
364 fd_set _wfdset, *wfdset = &_wfdset;
371 "CLIENT (fd %d): %s-directional Stream Test!\n\n" 372 "CLIENT (fd %d): Sending config to server on ctrl socket...\n",
377 fprintf (stderr,
"CLIENT: ERROR: test cfg sync failed -- aborting!");
383 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
389 printf (
"CLIENT (fd %d): Sending config to server on " 390 "test socket %d...\n", tsock->
fd, n);
395 tsock->
txbuf[i] = i & 0xff;
397 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
398 FD_SET (tsock->
fd, &wr_fdset);
399 FD_SET (tsock->
fd, &rd_fdset);
400 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
404 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
410 struct timeval timeout;
413 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
418 fprintf (stderr,
"\nCLIENT: ERROR: select() failed -- " 433 FD_ISSET (tsock->
fd, rfdset) &&
437 (uint8_t *) tsock->
rxbuf,
441 if (FD_ISSET (tsock->
fd, wfdset) &&
449 fprintf (stderr,
"\nCLIENT: ERROR: sock_test_write(%d) " 450 "failed -- aborting test!\n", tsock->
fd);
460 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
465 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
467 printf (
"CLIENT (fd %d): Sending config to server on ctrl socket...\n",
472 fprintf (stderr,
"CLIENT: ERROR: test cfg sync failed -- aborting!");
484 snprintf (buf,
sizeof (buf),
"CLIENT (fd %d) RESULTS", tsock->
fd);
500 printf (
" ctrl socket info\n" 504 " rxbuf size: %u (0x%08x)\n" 506 " txbuf size: %u (0x%08x)\n" 508 ctrl->
fd, (uint32_t) ctrl->
fd,
515 fprintf (stderr,
"CLIENT: ERROR: post-test cfg sync failed!");
517 printf (
"CLIENT (fd %d): %s-directional Stream Test Complete!\n" 530 printf (
"CLIENT: af_unix_echo_tx %d, af_unix_echo_rx %d\n",
540 printf (
"\nCLIENT (fd %d): Sending exit cfg to server...\n",
552 printf (
"\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->
fd);
558 printf (
"\nCLIENT: So long and thanks for all the fish!\n\n");
568 int i, rv, errno_val;
570 if (num_test_sockets < 1)
576 if (num_test_sockets < scm->num_test_sockets)
594 perror (
"ERROR in sock_test_connect_test_sockets()");
595 fprintf (stderr,
"CLIENT: ERROR: socket failed (errno = %d)!\n",
610 SOCK_DGRAM : SOCK_STREAM, 0);
615 perror (
"ERROR in sock_test_connect_test_sockets()");
616 fprintf (stderr,
"CLIENT: ERROR: socket failed (errno = %d)!\n",
621 rv = connect (tsock->
fd, (
struct sockaddr *) &scm->
server_addr,
627 perror (
"ERROR in sock_test_connect_test_sockets()");
628 fprintf (stderr,
"CLIENT: ERROR: connect failed " 629 "(errno = %d)!\n", errno_val);
632 if (fcntl (tsock->
fd, F_SETFL, O_NONBLOCK) < 0)
635 perror (
"ERROR in sock_test_connect_test_sockets()");
636 fprintf (stderr,
"CLIENT: ERROR: fcntl failed (errno = %d)!\n",
644 printf (
"CLIENT (fd %d): Test socket %d connected.\n",
650 printf (
"CLIENT: All sockets (%d) connected!\n", scm->
num_test_sockets + 1);
660 uint64_t txbuf_size = strtoull ((
const char *) p, NULL, 10);
671 fprintf (stderr,
"CLIENT: ERROR: Invalid txbuf size (%lu) < " 672 "minimum buf size (%u)!\n",
682 uint32_t num_writes = strtoul ((
const char *) p, NULL, 10);
692 fprintf (stderr,
"CLIENT: ERROR: invalid num writes: %u\n", num_writes);
702 uint32_t num_test_sockets = strtoul ((
const char *) p, NULL, 10);
704 if ((num_test_sockets > 0) &&
714 fprintf (stderr,
"CLIENT: ERROR: invalid num test sockets: " 726 uint64_t rxbuf_size = strtoull ((
const char *) p, NULL, 10);
736 fprintf (stderr,
"CLIENT: ERROR: Invalid rxbuf size (%lu) < " 737 "minimum buf size (%u)!\n",
809 "sock_test_client [OPTIONS] <ipaddr> <port>\n" 811 " -h Print this message and exit.\n" 813 " -u Use UDP transport layer\n" 814 " -c Print test config before test.\n" 815 " -w <dir> Write test results to <dir>.\n" 816 " -X Exit after running test.\n" 817 " -E Run Echo test.\n" 818 " -N <num-writes> Test Cfg: number of writes.\n" 819 " -R <rxbuf-size> Test Cfg: rx buffer size.\n" 820 " -T <txbuf-size> Test Cfg: tx buffer size.\n" 821 " -U Run Uni-directional test.\n" 822 " -B Run Bi-directional test.\n" 823 " -V Verbose mode.\n");
832 int c, rv, errno_val;
839 while ((c = getopt (argc, argv,
"chn:w:XE:I:N:R:T:UBV6D")) != -1)
850 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 857 fprintf (stderr,
"CLIENT: ERROR: Invalid number of " 858 "sockets (%d) specified for option -%c!\n" 859 " Valid range is 1 - %d\n",
866 fprintf (stderr,
"CLIENT: Writing test results to files is TBD.\n");
876 fprintf (stderr,
"CLIENT: ERROR: Option -%c value " 877 "larger than txbuf size (%d)!\n",
889 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 895 fprintf (stderr,
"CLIENT: ERROR: value greater than max " 905 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 916 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 924 (uint8_t **) & ctrl->
rxbuf,
929 fprintf (stderr,
"CLIENT: ERROR: rxbuf size (%lu) " 930 "less than minumum (%u)\n",
941 fprintf (stderr,
"CLIENT: ERROR: Invalid value " 942 "for option -%c!\n", c);
949 (uint8_t **) & ctrl->
txbuf,
956 fprintf (stderr,
"CLIENT: ERROR: txbuf size (%lu) " 957 "less than minumum (%u)!\n",
992 fprintf (stderr,
"CLIENT: ERROR: Option -%c " 993 "requires an argument.\n", optopt);
997 if (isprint (optopt))
998 fprintf (stderr,
"CLIENT: ERROR: Unknown " 999 "option `-%c'.\n", optopt);
1001 fprintf (stderr,
"CLIENT: ERROR: Unknown " 1002 "option character `\\x%x'.\n", optopt);
1010 if (argc < (optind + 2))
1012 fprintf (stderr,
"CLIENT: ERROR: Insufficient number of arguments!\n");
1022 perror (
"ERROR in main()");
1023 fprintf (stderr,
"CLIENT: ERROR: socket " 1024 "failed (errno = %d)!\n", errno_val);
1031 struct sockaddr_in6 *server_addr =
1034 server_addr->sin6_family = AF_INET6;
1035 inet_pton (AF_INET6, argv[optind++], &(server_addr->sin6_addr));
1036 server_addr->sin6_port = htons (atoi (argv[optind]));
1040 struct sockaddr_in *server_addr =
1043 server_addr->sin_family = AF_INET;
1044 inet_pton (AF_INET, argv[optind++], &(server_addr->sin_addr));
1045 server_addr->sin_port = htons (atoi (argv[optind]));
1050 printf (
"\nCLIENT: Connecting to server...\n");
1052 rv = connect (ctrl->
fd, (
struct sockaddr *) &scm->
server_addr,
1058 perror (
"ERROR in main()");
1059 fprintf (stderr,
"CLIENT: ERROR: connect failed (errno = %d)!\n",
1065 printf (
"CLIENT (fd %d): Control socket connected.\n", ctrl->
fd);
1126 printf (
"\nCLIENT: Type some characters and hit <return>\n" 1131 if (strlen (ctrl->
txbuf) == 1)
1133 printf (
"\nCLIENT: Nothing 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 echo_test_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
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
vcl_test_session_t * test_socket
sock_client_main_t sock_client_main
#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