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 sizeof (serveraddr.sun_path));
257 rv = connect (fd, (
struct sockaddr *) &serveraddr, SUN_LEN (&serveraddr));
261 perror (
"ERROR in echo_test_client(): connect() failed");
262 fprintf (stderr,
"CLIENT: ERROR: connect(fd %d, \"%s\", %lu) " 264 SUN_LEN (&serveraddr), errno_val);
271 timeout.tv_usec = 250000;
272 select (0, NULL, NULL, NULL, &timeout);
273 rv = write (fd, buffer, nbytes);
277 perror (
"ERROR in echo_test_client(): write() failed");
278 fprintf (stderr,
"CLIENT: ERROR: write(fd %d, \"%s\", %lu) " 279 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
282 else if (rv < nbytes)
284 fprintf (stderr,
"CLIENT: ERROR: write(fd %d, \"%s\", %lu) " 285 "returned %d!\n", fd, buffer, nbytes, rv);
289 printf (
"CLIENT (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
290 memset (buffer, 0,
sizeof (buffer));
291 rv = read (fd, buffer, nbytes);
295 perror (
"ERROR in echo_test_client(): read() failed");
296 fprintf (stderr,
"CLIENT: ERROR: read(fd %d, %p, %lu) " 297 "failed (errno = %d)!\n", fd, buffer, nbytes, errno_val);
300 else if (rv < nbytes)
302 fprintf (stderr,
"CLIENT: ERROR: read(fd %d, %p, %lu) " 303 "returned %d!\n", fd, buffer, nbytes, rv);
309 printf (
"CLIENT (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
313 printf (
"CLIENT (AF_UNIX): ERROR: RX (%d bytes) - '%s'\n", rv, buffer);
331 snprintf (buf,
sizeof (buf),
"CLIENT (fd %d) RESULTS", tsock->
fd);
349 printf (
" ctrl socket info\n" 353 " rxbuf size: %u (0x%08x)\n" 355 " txbuf size: %u (0x%08x)\n" 357 ctrl->
fd, (uint32_t) ctrl->
fd,
374 fd_set wr_fdset, rd_fdset;
375 fd_set _wfdset, *wfdset = &_wfdset;
382 "CLIENT (fd %d): %s-directional Stream Test!\n\n" 383 "CLIENT (fd %d): Sending config to server on ctrl socket...\n",
388 fprintf (stderr,
"CLIENT: ERROR: test cfg sync failed -- aborting!");
394 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
400 printf (
"CLIENT (fd %d): Sending config to server on " 401 "test socket %d...\n", tsock->
fd, n);
406 tsock->
txbuf[i] = i & 0xff;
408 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
409 FD_SET (tsock->
fd, &wr_fdset);
410 FD_SET (tsock->
fd, &rd_fdset);
411 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
415 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
423 vppcom_select (nfds, (
unsigned long *) rfdset,
424 (
unsigned long *) wfdset, NULL, 0);
427 struct timeval timeout;
430 rv = select (nfds, rfdset, wfdset, NULL, &timeout);
436 fprintf (stderr,
"\nCLIENT: ERROR: select() failed -- " 451 FD_ISSET (tsock->
fd, rfdset) &&
455 (uint8_t *) tsock->
rxbuf,
459 if (FD_ISSET (tsock->
fd, wfdset) &&
467 fprintf (stderr,
"\nCLIENT: ERROR: sock_test_write(%d) " 468 "failed -- aborting test!\n", tsock->
fd);
478 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
483 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
485 printf (
"CLIENT (fd %d): Sending config to server on ctrl socket...\n",
490 fprintf (stderr,
"CLIENT: ERROR: test cfg sync failed -- aborting!");
502 snprintf (buf,
sizeof (buf),
"CLIENT (fd %d) RESULTS", tsock->
fd);
518 printf (
" ctrl socket info\n" 522 " rxbuf size: %u (0x%08x)\n" 524 " txbuf size: %u (0x%08x)\n" 526 ctrl->
fd, (uint32_t) ctrl->
fd,
533 fprintf (stderr,
"CLIENT: ERROR: post-test cfg sync failed!");
535 printf (
"CLIENT (fd %d): %s-directional Stream Test Complete!\n" 549 printf (
"CLIENT: af_unix_echo_tx %d, af_unix_echo_rx %d\n",
560 printf (
"\nCLIENT (fd %d): Sending exit cfg to server...\n",
572 printf (
"\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->
fd);
578 printf (
"\nCLIENT: So long and thanks for all the fish!\n\n");
588 int i, rv, errno_val;
590 if (num_test_sockets < 1)
596 if (num_test_sockets < scm->num_test_sockets)
602 vppcom_session_close (tsock->
fd);
618 perror (
"ERROR in sock_test_connect_test_sockets()");
619 fprintf (stderr,
"CLIENT: ERROR: socket failed (errno = %d)!\n",
645 SOCK_DGRAM : SOCK_STREAM, 0);
650 perror (
"ERROR in sock_test_connect_test_sockets()");
651 fprintf (stderr,
"CLIENT: ERROR: socket failed (errno = %d)!\n",
657 rv = vppcom_session_connect (tsock->
fd, &scm->server_endpt);
664 rv = connect (tsock->
fd, (
struct sockaddr *) &scm->
server_addr,
670 perror (
"ERROR in sock_test_connect_test_sockets()");
671 fprintf (stderr,
"CLIENT: ERROR: connect failed " 672 "(errno = %d)!\n", errno_val);
675 if (fcntl (tsock->
fd, F_SETFL, O_NONBLOCK) < 0)
678 perror (
"ERROR in sock_test_connect_test_sockets()");
679 fprintf (stderr,
"CLIENT: ERROR: fcntl failed (errno = %d)!\n",
687 printf (
"CLIENT (fd %d): Test socket %d connected.\n",
693 printf (
"CLIENT: All sockets (%d) connected!\n", scm->
num_test_sockets + 1);
702 printf (
"CLIENT: Test configuration commands:" 704 "\t\t\tDisplay help." 706 "\t\t\tExit test client & server." 708 "\t\t\tShow the current test cfg." 710 "\t\t\tRun the Uni-directional test." 712 "\t\t\tRun the Bi-directional test." 714 "\t\t\tToggle verbose setting." 716 "<rxbuf size>\tRx buffer size (bytes)." 718 "<txbuf size>\tTx buffer size (bytes)." 720 "<# of writes>\tNumber of txbuf writes to server." "\n");
729 uint64_t txbuf_size = strtoull ((
const char *) p, NULL, 10);
740 fprintf (stderr,
"CLIENT: ERROR: Invalid txbuf size (%lu) < " 741 "minimum buf size (%u)!\n",
751 uint32_t num_writes = strtoul ((
const char *) p, NULL, 10);
761 fprintf (stderr,
"CLIENT: ERROR: invalid num writes: %u\n", num_writes);
771 uint32_t num_test_sockets = strtoul ((
const char *) p, NULL, 10);
773 if ((num_test_sockets > 0) &&
783 fprintf (stderr,
"CLIENT: ERROR: invalid num test sockets: " 795 uint64_t rxbuf_size = strtoull ((
const char *) p, NULL, 10);
805 fprintf (stderr,
"CLIENT: ERROR: Invalid rxbuf size (%lu) < " 806 "minimum buf size (%u)!\n",
878 "sock_test_client [OPTIONS] <ipaddr> <port>\n" 880 " -h Print this message and exit.\n" 882 " -u Use UDP transport layer\n" 883 " -c Print test config before test.\n" 884 " -w <dir> Write test results to <dir>.\n" 885 " -X Exit after running test.\n" 886 " -E Run Echo test.\n" 887 " -N <num-writes> Test Cfg: number of writes.\n" 888 " -R <rxbuf-size> Test Cfg: rx buffer size.\n" 889 " -T <txbuf-size> Test Cfg: tx buffer size.\n" 890 " -U Run Uni-directional test.\n" 891 " -B Run Bi-directional test.\n" 892 " -V Verbose mode.\n");
901 int c, rv, errno_val;
908 while ((c = getopt (argc, argv,
"chn:w:XE:I:N:R:T:UBV6D")) != -1)
919 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 926 fprintf (stderr,
"CLIENT: ERROR: Invalid number of " 927 "sockets (%d) specified for option -%c!\n" 928 " Valid range is 1 - %d\n",
935 fprintf (stderr,
"CLIENT: Writing test results to files is TBD.\n");
945 fprintf (stderr,
"CLIENT: ERROR: Option -%c value " 946 "larger than txbuf size (%d)!\n",
958 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 964 fprintf (stderr,
"CLIENT: ERROR: value greater than max " 974 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 985 fprintf (stderr,
"CLIENT: ERROR: Invalid value for " 993 (uint8_t **) & ctrl->
rxbuf,
998 fprintf (stderr,
"CLIENT: ERROR: rxbuf size (%lu) " 999 "less than minumum (%u)\n",
1010 fprintf (stderr,
"CLIENT: ERROR: Invalid value " 1011 "for option -%c!\n", c);
1018 (uint8_t **) & ctrl->
txbuf,
1025 fprintf (stderr,
"CLIENT: ERROR: txbuf size (%lu) " 1026 "less than minumum (%u)!\n",
1061 fprintf (stderr,
"CLIENT: ERROR: Option -%c " 1062 "requires an argument.\n", optopt);
1066 if (isprint (optopt))
1067 fprintf (stderr,
"CLIENT: ERROR: Unknown " 1068 "option `-%c'.\n", optopt);
1070 fprintf (stderr,
"CLIENT: ERROR: Unknown " 1071 "option character `\\x%x'.\n", optopt);
1079 if (argc < (optind + 2))
1081 fprintf (stderr,
"CLIENT: ERROR: Insufficient number of arguments!\n");
1086 ctrl->
fd = vppcom_app_create (
"vcl_test_client");
1112 perror (
"ERROR in main()");
1113 fprintf (stderr,
"CLIENT: ERROR: socket " 1114 "failed (errno = %d)!\n", errno_val);
1121 struct sockaddr_in6 *server_addr =
1124 server_addr->sin6_family = AF_INET6;
1125 inet_pton (AF_INET6, argv[optind++], &(server_addr->sin6_addr));
1126 server_addr->sin6_port = htons (atoi (argv[optind]));
1130 struct sockaddr_in *server_addr =
1133 server_addr->sin_family = AF_INET;
1134 inet_pton (AF_INET, argv[optind++], &(server_addr->sin_addr));
1135 server_addr->sin_port = htons (atoi (argv[optind]));
1141 struct sockaddr_in6 *server_addr =
1143 scm->server_endpt.is_ip4 = 0;
1144 scm->server_endpt.ip = (uint8_t *) & server_addr->sin6_addr;
1145 scm->server_endpt.port = (uint16_t) server_addr->sin6_port;
1149 struct sockaddr_in *server_addr =
1151 scm->server_endpt.is_ip4 = 1;
1152 scm->server_endpt.ip = (uint8_t *) & server_addr->sin_addr;
1153 scm->server_endpt.port = (uint16_t) server_addr->sin_port;
1159 printf (
"\nCLIENT: Connecting to server...\n");
1162 rv = vppcom_session_connect (ctrl->
fd, &scm->server_endpt);
1176 perror (
"ERROR in main()");
1177 fprintf (stderr,
"CLIENT: ERROR: connect failed (errno = %d)!\n",
1183 printf (
"CLIENT (fd %d): Control socket connected.\n", ctrl->
fd);
1244 printf (
"\nCLIENT: Type some characters and hit <return>\n" 1249 if (strlen (ctrl->
txbuf) == 1)
1251 printf (
"\nCLIENT: Nothing to send! Please try again...\n");
1263 vppcom_session_close (ctrl->
fd);
1264 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