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);
122 stabrt (
"write(fd %d, \"%s\", %lu) returned %d!", fd,
buffer, nbytes,
rv);
131 stabrt (
"read(fd %d, %p, %lu) returned %d!\n", fd,
buffer, nbytes,
rv);
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",
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);
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");
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");