20 #include <sys/types.h> 21 #include <sys/socket.h> 24 #include <arpa/inet.h> 32 struct sockaddr_in server_addr;
48 int rx_bytes, tx_bytes;
57 fprintf (stderr,
"ERROR: write test cfg failed (%d)!\n", tx_bytes);
68 fprintf (stderr,
"ERROR: Bad server reply cfg -- aborting!\n");
73 printf (
"CLIENT (fd %d): Got config back from server.\n", socket->
fd);
80 "ERROR: Invalid config received from server -- aborting!\n");
96 int rx_bytes, tx_bytes, nbytes;
100 fd_set wr_fdset, rd_fdset;
101 fd_set _wfdset, *wfdset = &_wfdset;
102 fd_set _rfdset, *rfdset = &_rfdset;
106 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
116 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
118 FD_SET (tsock->
fd, &wr_fdset);
119 FD_SET (tsock->
fd, &rd_fdset);
120 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
124 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
131 rv =
vppcom_select (nfds, (uint64_t *) rfdset, (uint64_t *) wfdset,
135 struct timeval timeout;
138 rv = select (nfds, rfdset, wfdset,
NULL, &timeout);
144 fprintf (stderr,
"\nERROR: select() failed -- aborting test!\n");
157 if (FD_ISSET (tsock->
fd, wfdset) &&
166 fprintf (stderr,
"\nERROR: sock_test_write(%d) failed " 167 "-- aborting test!\n", tsock->
fd);
171 printf (
"CLIENT (fd %d): TX (%d bytes) - '%s'\n",
172 tsock->
fd, tx_bytes, tsock->
txbuf);
175 if ((FD_ISSET (tsock->
fd, rfdset)) &&
180 nbytes, &tsock->
stats);
183 printf (
"CLIENT (fd %d): RX (%d bytes) - '%s'\n",
184 tsock->
fd, rx_bytes, tsock->
rxbuf);
188 (
"WARNING: bytes read (%lu) != bytes written (%lu)!\n",
195 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
200 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
211 sprintf (buf,
"CLIENT (fd %d) RESULTS", tsock->
fd);
229 printf (
" ctrl socket info\n" 233 " rxbuf size: %u (0x%08x)\n" 235 " txbuf size: %u (0x%08x)\n" 237 ctrl->
fd, (uint32_t) ctrl->
fd,
254 fd_set wr_fdset, rd_fdset;
255 fd_set _wfdset, *wfdset = &_wfdset;
262 "CLIENT (fd %d): %s-directional Stream Test!\n\n" 263 "CLIENT (fd %d): Sending config to server on ctrl socket...\n",
268 fprintf (stderr,
"ERROR: test cfg sync failed -- aborting!");
274 memset (&ctrl->
stats, 0, sizeof (ctrl->
stats));
280 printf (
"CLIENT (fd %d): Sending config to server on " 281 "test socket %d...\n", tsock->
fd, n);
286 tsock->
txbuf[i] = i & 0xff;
288 memset (&tsock->
stats, 0, sizeof (tsock->
stats));
289 FD_SET (tsock->
fd, &wr_fdset);
290 FD_SET (tsock->
fd, &rd_fdset);
291 nfds = ((tsock->
fd + 1) > nfds) ? (tsock->
fd + 1) : nfds;
295 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
start);
302 rv =
vppcom_select (nfds, (uint64_t *) rfdset, (uint64_t *) wfdset,
306 struct timeval timeout;
309 rv = select (nfds, rfdset, wfdset,
NULL, &timeout);
315 fprintf (stderr,
"\nERROR: select() failed -- aborting test!\n");
328 if (FD_ISSET (tsock->
fd, wfdset) &&
337 fprintf (stderr,
"\nERROR: sock_test_write(%d) failed " 338 "-- aborting test!\n", tsock->
fd);
344 FD_ISSET (tsock->
fd, rfdset) &&
348 (uint8_t *) tsock->
rxbuf,
357 clock_gettime (CLOCK_REALTIME, &tsock->
stats.
stop);
362 clock_gettime (CLOCK_REALTIME, &ctrl->
stats.
stop);
364 printf (
"CLIENT (fd %d): Sending config to server on ctrl socket...\n",
369 fprintf (stderr,
"ERROR: test cfg sync failed -- aborting!");
381 sprintf (buf,
"CLIENT (fd %d) RESULTS", tsock->
fd);
397 printf (
" ctrl socket info\n" 401 " rxbuf size: %u (0x%08x)\n" 403 " txbuf size: %u (0x%08x)\n" 405 ctrl->
fd, (uint32_t) ctrl->
fd,
412 fprintf (stderr,
"ERROR: post-test cfg sync failed!");
414 printf (
"CLIENT (fd %d): %s-directional Stream Test Complete!\n" 435 printf (
"\nCLIENT (fd %d): Sending exit cfg to server...\n",
447 printf (
"\nCLIENT (fd %d): Sending exit cfg to server...\n", ctrl->
fd);
453 printf (
"\nCLIENT: So long and thanks for all the fish!\n\n");
463 int i, rv, errno_val;
465 if (num_test_sockets < 1)
471 if (num_test_sockets < scm->num_test_sockets)
493 perror (
"ERROR in sock_test_connect_test_sockets()");
494 fprintf (stderr,
"ERROR: socket failed (errno = %d)!\n", errno_val);
499 memset (tsock, 0,
sizeof (*tsock));
515 tsock->
fd = socket (AF_INET, SOCK_STREAM, 0);
520 perror (
"ERROR in sock_test_connect_test_sockets()");
521 fprintf (stderr,
"ERROR: socket failed (errno = %d)!\n",
536 perror (
"ERROR in main()");
537 fprintf (stderr,
"ERROR: connect failed (errno = %d)!\n",
544 printf (
"CLIENT (fd %d): Test socket %d connected.\n",
550 printf (
"CLIENT: All sockets (%d) connected!\n", scm->
num_test_sockets + 1);
559 printf (
"Test configuration commands:" 561 "\t\t\tDisplay help." 563 "\t\t\tExit test client & server." 565 "\t\t\tShow the current test cfg." 567 "\t\t\tRun the Uni-directional test." 569 "\t\t\tRun the Bi-directional test." 571 "\t\t\tToggle verbose setting." 573 "<rxbuf size>\tRx buffer size (bytes)." 575 "<txbuf size>\tTx buffer size (bytes)." 577 "<# of writes>\tNumber of txbuf writes to server." "\n");
586 uint64_t txbuf_size = strtoull ((
const char *) p,
NULL, 10);
598 "ERROR: Invalid txbuf size (%lu) < minimum buf size (%u)!\n",
608 uint32_t num_writes = strtoul ((
const char *) p,
NULL, 10);
618 fprintf (stderr,
"ERROR: invalid num writes: %u\n", num_writes);
628 uint32_t num_test_sockets = strtoul ((
const char *) p,
NULL, 10);
630 if ((num_test_sockets > 0) &&
639 fprintf (stderr,
"ERROR: invalid num test sockets: %u, (%d max)\n",
650 uint64_t rxbuf_size = strtoull ((
const char *) p,
NULL, 10);
661 "ERROR: Invalid rxbuf size (%lu) < minimum buf size (%u)!\n",
729 "sock_test_client [OPTIONS] <ipaddr> <port>\n" 731 " -h Print this message and exit.\n" 732 " -c Print test config before test.\n" 733 " -w <dir> Write test results to <dir>.\n" 734 " -X Exit after running test.\n" 735 " -E Run Echo test.\n" 736 " -N <num-writes> Test Cfg: number of writes.\n" 737 " -R <rxbuf-size> Test Cfg: rx buffer size.\n" 738 " -T <txbuf-size> Test Cfg: tx buffer size.\n" 739 " -U Run Uni-directional test.\n" 740 " -B Run Bi-directional test.\n" 741 " -V Verbose mode.\n");
750 int c, rv, errno_val;
757 while ((c = getopt (argc, argv,
"chn:w:XE:I:N:R:T:UBV")) != -1)
768 fprintf (stderr,
"ERROR: Invalid value for option -%c!\n", c);
774 fprintf (stderr,
"ERROR: Invalid number of sockets (%d)" 775 "specified for option -%c!\n" 776 " Valid range is 1 - %d\n",
783 fprintf (stderr,
"Writing test results to files is TBD.\n");
794 "ERROR: Option -%c value larger than txbuf size (%d)!\n",
798 strcpy (ctrl->
txbuf, optarg);
806 fprintf (stderr,
"ERROR: Invalid value for option -%c!\n", c);
811 fprintf (stderr,
"ERROR: value greater than max number test" 821 fprintf (stderr,
"ERROR: Invalid value for option -%c!\n", c);
831 fprintf (stderr,
"ERROR: Invalid value for option -%c!\n", c);
838 (uint8_t **) & ctrl->
rxbuf,
844 "ERROR: rxbuf size (%lu) less than minumum (%u)\n",
855 fprintf (stderr,
"ERROR: Invalid value for option -%c!\n", c);
862 (uint8_t **) & ctrl->
txbuf,
870 "ERROR: txbuf size (%lu) less than minumum (%u)!\n",
897 fprintf (stderr,
"ERROR: Option -%c requires an argument.\n",
902 if (isprint (optopt))
903 fprintf (stderr,
"ERROR: Unknown option `-%c'.\n", optopt);
905 fprintf (stderr,
"ERROR: Unknown option character `\\x%x'.\n",
914 if (argc < (optind + 2))
916 fprintf (stderr,
"ERROR: Insufficient number of arguments!\n");
938 ctrl->
fd = socket (AF_INET, SOCK_STREAM, 0);
944 perror (
"ERROR in main()");
945 fprintf (stderr,
"ERROR: socket failed (errno = %d)!\n", errno_val);
952 inet_pton (AF_INET, argv[optind++], &(scm->
server_addr.sin_addr));
953 scm->
server_addr.sin_port = htons (atoi (argv[optind]));
957 scm->server_endpt.is_ip4 = (scm->
server_addr.sin_family == AF_INET);
958 scm->server_endpt.ip = (uint8_t *) & scm->
server_addr.sin_addr;
959 scm->server_endpt.port = (uint16_t) scm->
server_addr.sin_port;
964 printf (
"\nCLIENT: Connecting to server...\n");
976 perror (
"ERROR in main()");
977 fprintf (stderr,
"ERROR: connect failed (errno = %d)!\n",
982 printf (
"CLIENT (fd %d): Control socket connected.\n", ctrl->
fd);
1043 printf (
"\nType some characters and hit <return>\n" 1048 if (strlen (ctrl->
txbuf) == 1)
1050 printf (
"\nCLIENT: Nothing to send! Please try again...\n");
sll srl srl sll sra u16x4 i
int vppcom_app_create(char *app_name)
#define SOCK_TEST_TOKEN_EXIT
#define SOCK_TEST_TOKEN_RXBUF_SIZE
int vppcom_session_create(u32 vrf, u8 proto, u8 is_nonblocking)
#define SOCK_TEST_TOKEN_RUN_UNI
static void stream_test_client(sock_test_t test)
int main(int argc, char **argv)
static int sock_test_write(int fd, uint8_t *buf, uint32_t nbytes, sock_test_stats_t *stats, uint32_t verbose)
#define SOCK_TEST_CFG_CTRL_MAGIC
int vppcom_session_connect(uint32_t session_index, vppcom_endpt_t *server_ep)
static void sock_test_buf_alloc(sock_test_cfg_t *cfg, uint8_t is_rxbuf, uint8_t **buf, uint32_t *bufsize)
static sock_test_t parse_input()
static void sock_test_cfg_init(sock_test_cfg_t *cfg)
#define SOCK_TEST_BANNER_STRING
static int sock_test_cfg_sync(sock_test_socket_t *socket)
void vppcom_app_destroy(void)
static void exit_client(void)
#define SOCK_TEST_TOKEN_NUM_TEST_SCKTS
static void sock_test_cfg_dump(sock_test_cfg_t *cfg, uint8_t is_client)
#define SOCK_TEST_TOKEN_SHOW_CFG
static int sock_test_connect_test_sockets(uint32_t num_test_sockets)
uint32_t num_test_sockets
#define SOCK_TEST_CFG_MAX_TEST_SCKTS
#define SOCK_TEST_TOKEN_NUM_WRITES
static void echo_test_client()
static void cfg_verbose_toggle(void)
#define SOCK_TEST_TOKEN_VERBOSE
int vppcom_select(unsigned long n_bits, unsigned long *read_map, unsigned long *write_map, unsigned long *except_map, double time_to_wait)
static void sock_test_stats_dump(char *header, sock_test_stats_t *stats, uint8_t show_rx, uint8_t show_tx, uint8_t verbose)
#define SOCK_TEST_TOKEN_TXBUF_SIZE
uint32_t num_test_sockets
#define SOCK_TEST_CFG_BUF_SIZE_MIN
static void cfg_rxbuf_size_set(void)
static void sock_test_socket_buf_alloc(sock_test_socket_t *socket)
static void cfg_num_writes_set(void)
sock_test_socket_t * test_socket
#define SOCK_TEST_TOKEN_RUN_BI
static int sock_test_cfg_verify(sock_test_cfg_t *cfg, sock_test_cfg_t *valid_cfg)
static void cfg_txbuf_size_set(void)
static int sock_test_read(int fd, uint8_t *buf, uint32_t nbytes, sock_test_stats_t *stats)
sock_client_main_t sock_client_main
struct sockaddr_in server_addr
#define SOCK_TEST_SEPARATOR_STRING
static void dump_help(void)
static void sock_test_stats_accumulate(sock_test_stats_t *accum, sock_test_stats_t *incr)
#define SOCK_TEST_TOKEN_HELP
void print_usage_and_exit(void)
static void cfg_num_test_sockets_set(void)
int vppcom_session_close(uint32_t session_index)
#define VPPCOM_VRF_DEFAULT
sock_test_socket_t ctrl_socket