16 #ifndef __sock_test_h__ 17 #define __sock_test_h__ 24 #define SOCK_TEST_TOKEN_HELP "#H" 25 #define SOCK_TEST_TOKEN_EXIT "#X" 26 #define SOCK_TEST_TOKEN_VERBOSE "#V" 27 #define SOCK_TEST_TOKEN_TXBUF_SIZE "#T:" 28 #define SOCK_TEST_TOKEN_NUM_TEST_SCKTS "#I:" 29 #define SOCK_TEST_TOKEN_NUM_WRITES "#N:" 30 #define SOCK_TEST_TOKEN_RXBUF_SIZE "#R:" 31 #define SOCK_TEST_TOKEN_SHOW_CFG "#C" 32 #define SOCK_TEST_TOKEN_RUN_UNI "#U" 33 #define SOCK_TEST_TOKEN_RUN_BI "#B" 35 #define SOCK_TEST_BANNER_STRING \ 36 "============================================\n" 37 #define SOCK_TEST_SEPARATOR_STRING \ 38 " -----------------------------\n" 40 #define ONE_GIG (1024*1024*1024) 41 #define SOCK_TEST_SERVER_PORT 22000 42 #define SOCK_TEST_LOCALHOST_IPADDR "127.0.0.1" 44 #define SOCK_TEST_CFG_CTRL_MAGIC 0xfeedface 45 #define SOCK_TEST_CFG_NUM_WRITES_DEF 1000000 46 #define SOCK_TEST_CFG_TXBUF_SIZE_DEF 8192 47 #define SOCK_TEST_CFG_RXBUF_SIZE_DEF (64*SOCK_TEST_CFG_TXBUF_SIZE_DEF) 48 #define SOCK_TEST_CFG_BUF_SIZE_MIN 128 49 #define SOCK_TEST_CFG_MAX_TEST_SCKTS 5 60 typedef struct __attribute__ ((packed))
83 struct timespec start;
145 uint8_t *lb = realloc (*buf, (
size_t) alloc_size);
158 int errno_val = errno;
159 perror (
"ERROR in sock_test_buf_alloc()");
160 fprintf (stderr,
"ERROR: Buffer allocation failed (errno = %d)!\n" 161 " Using buffer size %d instead of desired" 162 " size (%d)\n", errno_val, *bufsize, alloc_size);
207 printf (
" test config (%p):\n" 210 "%-5s test: %s (%d)\n" 211 " ctrl handle: %d (0x%x)\n" 212 "%-5s num test sockets: %u (0x%08x)\n" 213 "%-5s verbose: %s (%d)\n" 214 "%-5s rxbuf size: %lu (0x%08lx)\n" 215 "%-5s txbuf size: %lu (0x%08lx)\n" 216 "%-5s num writes: %lu (0x%08lx)\n" 217 " client tx bytes: %lu (0x%08lx)\n" 219 (
void *) cfg, cfg->
magic,
241 uint8_t show_rx, uint8_t show_tx,
244 struct timespec diff;
245 double duration, rate;
246 uint64_t total_bytes;
248 if ((stats->
stop.tv_nsec - stats->
start.tv_nsec) < 0)
250 diff.tv_sec = stats->
stop.tv_sec - stats->
start.tv_sec - 1;
251 diff.tv_nsec = stats->
stop.tv_nsec - stats->
start.tv_nsec + 1000000000;
255 diff.tv_sec = stats->
stop.tv_sec - stats->
start.tv_sec;
256 diff.tv_nsec = stats->
stop.tv_nsec - stats->
start.tv_nsec;
258 duration = (double) diff.tv_sec + (1e-9 * diff.tv_nsec);
261 rate = (double) total_bytes * 8 / duration /
ONE_GIG;
262 printf (
"\n%s: Streamed %lu bytes\n" 263 " in %lf seconds (%lf Gbps %s-duplex)!\n",
264 header, total_bytes, duration, rate,
265 (show_rx && show_tx) ?
"full" :
"half");
270 " tx stats (0x%p):\n" 272 " writes: %lu (0x%08lx)\n" 273 " tx bytes: %lu (0x%08lx)\n" 274 " tx eagain: %u (0x%08x)\n" 275 " tx incomplete: %u (0x%08x)\n",
284 " rx stats (0x%p):\n" 286 " reads: %lu (0x%08lx)\n" 287 " rx bytes: %lu (0x%08lx)\n" 288 " rx eagain: %u (0x%08x)\n" 289 " rx incomplete: %u (0x%08x)\n",
296 printf (
" start.tv_sec: %ld\n" 297 " start.tv_nsec: %ld\n" 298 " stop.tv_sec: %ld\n" 299 " stop.tv_nsec: %ld\n",
301 stats->
stop.tv_sec, stats->
stop.tv_nsec);
310 int rx_bytes, errno_val;
325 rx_bytes = read (fd, buf, nbytes);
329 if ((rx_bytes == 0) ||
330 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
332 else if (rx_bytes < nbytes)
336 while ((rx_bytes == 0) ||
337 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
342 perror (
"ERROR in sock_test_read()");
343 fprintf (stderr,
"ERROR: socket read failed (errno = %d)!\n",
358 int nbytes_left = nbytes;
373 rv = write (fd, buf, nbytes_left);
377 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
388 if (tx_bytes != nbytes)
390 nbytes_left = nbytes_left - rv;
395 printf (
"WARNING: bytes written (%d) != bytes to write (%d)!\n",
400 }
while (tx_bytes != nbytes);
405 perror (
"ERROR in sock_test_write()");
406 fprintf (stderr,
"ERROR: socket write failed (errno = %d)!\n",
#define SOCK_TEST_TOKEN_RXBUF_SIZE
#define SOCK_TEST_TOKEN_RUN_UNI
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
static void sock_test_buf_alloc(sock_test_cfg_t *cfg, uint8_t is_rxbuf, uint8_t **buf, uint32_t *bufsize)
static void sock_test_cfg_init(sock_test_cfg_t *cfg)
#define SOCK_TEST_TOKEN_NUM_TEST_SCKTS
static void sock_test_cfg_dump(sock_test_cfg_t *cfg, uint8_t is_client)
uint32_t num_test_sockets
#define SOCK_TEST_TOKEN_NUM_WRITES
#define SOCK_TEST_TOKEN_VERBOSE
#define SOCK_TEST_CFG_NUM_WRITES_DEF
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
static void sock_test_socket_buf_alloc(sock_test_socket_t *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 int sock_test_read(int fd, uint8_t *buf, uint32_t nbytes, sock_test_stats_t *stats)
static char * sock_test_type_str(sock_test_t t)
#define SOCK_TEST_CFG_TXBUF_SIZE_DEF
#define SOCK_TEST_SEPARATOR_STRING
static void sock_test_stats_accumulate(sock_test_stats_t *accum, sock_test_stats_t *incr)
int vppcom_session_read(uint32_t session_index, void *buf, int n)
#define SOCK_TEST_CFG_RXBUF_SIZE_DEF
int vppcom_session_write(uint32_t session_index, void *buf, int n)