20 #include <sys/types.h> 21 #include <sys/socket.h> 24 #include <arpa/inet.h> 34 vppcom_endpt_t server_endpt;
39 struct sockaddr_storage server_addr;
57 int rx_bytes, tx_bytes;
65 printf (
"CLIENT (fd %d): Sending config sent to server.\n", socket->
fd);
72 fprintf (stderr,
"CLIENT (fd %d): ERROR: write test cfg failed (%d)!\n",
73 socket->
fd, tx_bytes);
84 fprintf (stderr,
"CLIENT (fd %d): ERROR: Bad server reply cfg " 85 "-- aborting!\n", socket->
fd);
91 fprintf (stderr,
"CLIENT (fd %d): ERROR: Invalid config received " 92 "from server!\n", socket->
fd);
95 fprintf (stderr,
"\tRx bytes %d != cfg size %lu\n",
101 fprintf (stderr,
"CLIENT (fd %d): Valid config sent to server.\n",
109 printf (
"CLIENT (fd %d): Got config back from server.\n", socket->
fd);
124 int rx_bytes, tx_bytes, nbytes;
128 fd_set wr_fdset, rd_fdset;
129 fd_set _wfdset, *wfdset = &_wfdset;
130 fd_set _rfdset, *rfdset = &_rfdset;
134 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
145 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
147 FD_SET (tsock->
fd, &wr_fdset);
148 FD_SET (tsock->
fd, &rd_fdset);
149 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
153 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
161 vppcom_select (nfds, (
unsigned long *) rfdset,
162 (
unsigned long *) wfdset,
NULL, 0);
165 struct timeval timeout;
168 rv = select (nfds, rfdset, wfdset,
NULL, &timeout);
174 fprintf (stderr,
"\nCLIENT: ERROR: select() failed -- " 188 if (FD_ISSET (tsock->
fd, wfdset) &&
197 fprintf (stderr,
"\nCLIENT: ERROR: sock_test_write(%d) " 198 "failed -- aborting test!\n", tsock->
fd);
202 printf (
"CLIENT (fd %d): TX (%d bytes) - '%s'\n",
203 tsock->
fd, tx_bytes, tsock->
txbuf);
206 if ((FD_ISSET (tsock->
fd, rfdset)) &&
211 nbytes, &tsock->
stats);
214 printf (
"CLIENT (fd %d): RX (%d bytes)\n", tsock->
fd,
218 printf (
"CLIENT: WARNING: bytes read (%lu) " 219 "!= bytes written (%lu)!\n",
226 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
231 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
236 struct sockaddr_un serveraddr;
239 struct timeval timeout;
243 fd = socket (AF_UNIX, SOCK_STREAM, 0);
247 perror (
"ERROR in echo_test_client(): socket(AF_UNIX) failed");
249 "CLIENT: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed " 250 "(errno = %d)!\n", errno_val);
253 memset (&serveraddr, 0,
sizeof (serveraddr));
254 serveraddr.sun_family = AF_UNIX;
256 rv = connect (fd, (
struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr));
260 perror (
"ERROR in echo_test_client(): connect() failed");
261 fprintf (stderr,
"CLIENT: ERROR: connect(fd %d, \"%s\", %lu) " 263 SUN_LEN (&serveraddr), errno_val);
270 timeout.tv_usec = 250000;
272 rv = write (fd, buffer, nbytes);
276 perror (
"ERROR in echo_test_client(): write() failed");
277 fprintf (stderr,
"CLIENT: ERROR: write(fd %d, \"%s\", %lu) " 278 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
281 else if (rv < nbytes)
283 fprintf (stderr,
"CLIENT: ERROR: write(fd %d, \"%s\", %lu) " 284 "returned %d!\n", fd, buffer, nbytes, rv);
288 printf (
"CLIENT (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
289 memset (buffer, 0,
sizeof (buffer));
290 rv = read (fd, buffer, nbytes);
294 perror (
"ERROR in echo_test_client(): read() failed");
295 fprintf (stderr,
"CLIENT: ERROR: read(fd %d, %p, %lu) " 296 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
299 else if (rv < nbytes)
301 fprintf (stderr,
"CLIENT: ERROR: read(fd %d, %p, %lu) " 302 "returned %d!\n", fd, buffer, nbytes, rv);
308 printf (
"CLIENT (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
312 printf (
"CLIENT (AF_UNIX): ERROR: RX (%d bytes) - '%s'\n", rv, buffer);
330 sprintf (buf,
"CLIENT (fd %d) RESULTS", tsock->
fd);
348 printf (
" ctrl socket info\n" 352 " rxbuf size: %u (0x%08x)\n" 354 " txbuf size: %u (0x%08x)\n" 356 ctrl->
fd, (uint32_t) ctrl->
fd,
373 fd_set wr_fdset, rd_fdset;
374 fd_set _wfdset, *wfdset = &_wfdset;
381 "CLIENT (fd %d): %s-directional Stream Test!\n\n" 382 "CLIENT (fd %d): Sending config to server on ctrl socket...\n",
387 fprintf (stderr,
"CLIENT: ERROR: test cfg sync failed -- aborting!");
393 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
399 printf (
"CLIENT (fd %d): Sending config to server on " 400 "test socket %d...\n", tsock->
fd, n);
405 tsock->
txbuf[i] = i & 0xff;
407 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
408 FD_SET (tsock->
fd, &wr_fdset);
409 FD_SET (tsock->
fd, &rd_fdset);
410 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
414 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
422 vppcom_select (nfds, (
unsigned long *) rfdset,
423 (
unsigned long *) wfdset,
NULL, 0);
426 struct timeval timeout;
429 rv = select (nfds, rfdset, wfdset,
NULL, &timeout);
435 fprintf (stderr,
"\nCLIENT: ERROR: select() failed -- " 450 FD_ISSET (tsock->
fd, rfdset) &&
454 (uint8_t *) tsock->
rxbuf,
458 if (FD_ISSET (tsock->
fd, wfdset) &&
466 fprintf (stderr,
"\nCLIENT: ERROR: sock_test_write(%d) " 467 "failed -- aborting test!\n", tsock->
fd);
477 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
482 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
484 printf (
"CLIENT (fd %d): Sending config to server on ctrl socket...\n",
489 fprintf (stderr,
"CLIENT: ERROR: test cfg sync failed -- aborting!");
501 sprintf (buf,
"CLIENT (fd %d) RESULTS", tsock->
fd);
517 printf (
" ctrl socket info\n" 521 " rxbuf size: %u (0x%08x)\n" 523 " txbuf size: %u (0x%08x)\n" 525 ctrl->
fd, (uint32_t) ctrl->
fd,
532 fprintf (stderr,
"CLIENT: ERROR: post-test cfg sync failed!");
534 printf (
"CLIENT (fd %d): %s-directional Stream Test Complete!\n" 548 printf (
"CLIENT: af_unix_echo_tx %d, af_unix_echo_rx %d\n",
559 printf (
"\nCLIENT (fd %d): Sending exit cfg to server...\n",
571 printf (
"\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->
fd);
577 printf (
"\nCLIENT: So long and thanks for all the fish!\n\n");
587 int i, rv, errno_val;
589 if (num_test_sockets < 1)
595 if (num_test_sockets < scm->num_test_sockets)
601 vppcom_session_close (tsock->
fd);
617 perror (
"ERROR in sock_test_connect_test_sockets()");
618 fprintf (stderr,
"CLIENT: ERROR: socket failed (errno = %d)!\n",
644 SOCK_DGRAM : SOCK_STREAM, 0);
649 perror (
"ERROR in sock_test_connect_test_sockets()");
650 fprintf (stderr,
"CLIENT: ERROR: socket failed (errno = %d)!\n",
656 rv = vppcom_session_connect (tsock->
fd, &scm->server_endpt);
663 rv = connect (tsock->
fd, (
struct sockaddr *) &scm->
server_addr,
669 perror (
"ERROR in sock_test_connect_test_sockets()");
670 fprintf (stderr,
"CLIENT: ERROR: connect failed " 671 "(errno = %d)!\n", errno_val);
674 if (fcntl (tsock->
fd, F_SETFL, O_NONBLOCK) < 0)
677 perror (
"ERROR in sock_test_connect_test_sockets()");
678 fprintf (stderr,
"CLIENT: ERROR: fcntl failed (errno = %d)!\n",
686 printf (
"CLIENT (fd %d): Test socket %d connected.\n",
692 printf (
"CLIENT: All sockets (%d) connected!\n", scm->
num_test_sockets + 1);
701 printf (
"CLIENT: Test configuration commands:" 703 "\t\t\tDisplay help." 705 "\t\t\tExit test client & server." 707 "\t\t\tShow the current test cfg." 709 "\t\t\tRun the Uni-directional test." 711 "\t\t\tRun the Bi-directional test." 713 "\t\t\tToggle verbose setting." 715 "<rxbuf size>\tRx buffer size (bytes)." 717 "<txbuf size>\tTx buffer size (bytes)." 719 "<# of writes>\tNumber of txbuf writes to server." "\n");
728 uint64_t txbuf_size = strtoull ((
const char *) p,
NULL, 10);
739 fprintf (stderr,
"CLIENT: ERROR: Invalid txbuf size (%lu) < " 740 "minimum buf size (%u)!\n",
750 uint32_t num_writes = strtoul ((
const char *) p,
NULL, 10);
760 fprintf (stderr,
"CLIENT: ERROR: invalid num writes: %u\n", num_writes);
770 uint32_t num_test_sockets = strtoul ((
const char *) p,
NULL, 10);
772 if ((num_test_sockets > 0) &&
782 fprintf (stderr,
"CLIENT: ERROR: invalid num test sockets: " 794 uint64_t rxbuf_size = strtoull ((
const char *) p,
NULL, 10);
804 fprintf (stderr,
"CLIENT: ERROR: Invalid rxbuf size (%lu) < " 805 "minimum buf size (%u)!\n",
877 "sock_test_client [OPTIONS] <ipaddr> <port>\n" 879 " -h Print this message and exit.\n" 881 " -u Use UDP transport layer\n" 882 " -c Print test config before test.\n" 883 " -w <dir> Write test results to <dir>.\n" 884 " -X Exit after running test.\n" 885 " -E Run Echo test.\n" 886 " -N <num-writes> Test Cfg: number of writes.\n" 887 " -R <rxbuf-size> Test Cfg: rx buffer size.\n" 888 " -T <txbuf-size> Test Cfg: tx buffer size.\n" 889 " -U Run Uni-directional test.\n" 890 " -B Run Bi-directional test.\n" 891 " -V Verbose mode.\n");
900 int c, rv, errno_val;
907 while ((c = getopt (argc, argv,
"chn:w:XE:I:N:R:T:UBV6D")) != -1)
918 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 925 fprintf (stderr,
"CLIENT: ERROR: Invalid number of " 926 "sockets (%d) specified for option -%c!\n" 927 " Valid range is 1 - %d\n",
934 fprintf (stderr,
"CLIENT: Writing test results to files is TBD.\n");
944 fprintf (stderr,
"CLIENT: ERROR: Option -%c value " 945 "larger than txbuf size (%d)!\n",
949 strcpy (ctrl->
txbuf, optarg);
957 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 963 fprintf (stderr,
"CLIENT: ERROR: value greater than max " 973 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 984 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 992 (uint8_t **) & ctrl->
rxbuf,
997 fprintf (stderr,
"CLIENT: ERROR: rxbuf size (%lu) " 998 "less than minumum (%u)\n",
1009 fprintf (stderr,
"CLIENT: ERROR: Invalid value " 1010 "for option -%c!\n", c);
1017 (uint8_t **) & ctrl->
txbuf,
1024 fprintf (stderr,
"CLIENT: ERROR: txbuf size (%lu) " 1025 "less than minumum (%u)!\n",
1060 fprintf (stderr,
"CLIENT: ERROR: Option -%c " 1061 "requires an argument.\n", optopt);
1065 if (isprint (optopt))
1066 fprintf (stderr,
"CLIENT: ERROR: Unknown " 1067 "option `-%c'.\n", optopt);
1069 fprintf (stderr,
"CLIENT: ERROR: Unknown " 1070 "option character `\\x%x'.\n", optopt);
1078 if (argc < (optind + 2))
1080 fprintf (stderr,
"CLIENT: ERROR: Insufficient number of arguments!\n");
1085 ctrl->
fd = vppcom_app_create (
"vcl_test_client");
1111 perror (
"ERROR in main()");
1112 fprintf (stderr,
"CLIENT: ERROR: socket " 1113 "failed (errno = %d)!\n", errno_val);
1120 struct sockaddr_in6 *server_addr =
1123 server_addr->sin6_family = AF_INET6;
1124 inet_pton (AF_INET6, argv[optind++], &(server_addr->sin6_addr));
1125 server_addr->sin6_port = htons (atoi (argv[optind]));
1129 struct sockaddr_in *server_addr =
1132 server_addr->sin_family = AF_INET;
1133 inet_pton (AF_INET, argv[optind++], &(server_addr->sin_addr));
1134 server_addr->sin_port = htons (atoi (argv[optind]));
1140 struct sockaddr_in6 *server_addr =
1142 scm->server_endpt.is_ip4 = 0;
1143 scm->server_endpt.ip = (uint8_t *) & server_addr->sin6_addr;
1144 scm->server_endpt.port = (uint16_t) server_addr->sin6_port;
1148 struct sockaddr_in *server_addr =
1150 scm->server_endpt.is_ip4 = 1;
1151 scm->server_endpt.ip = (uint8_t *) & server_addr->sin_addr;
1152 scm->server_endpt.port = (uint16_t) server_addr->sin_port;
1158 printf (
"\nCLIENT: Connecting to server...\n");
1161 rv = vppcom_session_connect (ctrl->
fd, &scm->server_endpt);
1175 perror (
"ERROR in main()");
1176 fprintf (stderr,
"CLIENT: ERROR: connect failed (errno = %d)!\n",
1182 printf (
"CLIENT (fd %d): Control socket connected.\n", ctrl->
fd);
1243 printf (
"\nCLIENT: Type some characters and hit <return>\n" 1248 if (strlen (ctrl->
txbuf) == 1)
1250 printf (
"\nCLIENT: Nothing to send! Please try again...\n");
1262 vppcom_session_close (ctrl->
fd);
1263 vppcom_app_destroy ();
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
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
sock_client_main_t vcl_client_main
#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
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
static void dump_help(void)
#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