#define MAX_MEMIF_BUFS 256
#define MAX_CONNS 50
+#define ICMPR_HEADROOM 64
+
int epfd;
int out_fd;
uint8_t enable_log;
if (md.link_up_down)
printf ("up\n");
else
- printf ("down\n");
+ {
+ printf ("down\n");
+ printf ("\treason: %s\n", md.error);
+ }
}
free (buf);
}
on_connect (memif_conn_handle_t conn, void *private_ctx)
{
INFO ("memif connected!");
- memif_refill_queue (conn, 0, -1, 0);
+ memif_refill_queue (conn, 0, -1, ICMPR_HEADROOM);
enable_log = 1;
return 0;
}
/* user needs to watch new fd or stop watching fd that is about to be closed.
control fd will be modified during connection establishment to minimize CPU usage */
int
-control_fd_update (int fd, uint8_t events)
+control_fd_update (int fd, uint8_t events, void *ctx)
{
/* convert memif event definitions to epoll events */
if (events & MEMIF_FD_EVENT_DEL)
int err = MEMIF_ERR_SUCCESS, ret_val;
uint16_t rx = 0, tx = 0;
- uint16_t fb = 0;
int i = 0; /* rx buffer iterator */
int j = 0; /* tx bufferiterator */
tx--;
}
- err = memif_refill_queue (c->conn, qid, rx, 0);
+ err = memif_refill_queue (c->conn, qid, rx, ICMPR_HEADROOM);
if (err != MEMIF_ERR_SUCCESS)
INFO ("memif_buffer_free: %s", memif_strerror (err));
rx -= rx;
- DBG ("freed %d buffers. %u/%u alloc/free buffers",
- rx, rx, MAX_MEMIF_BUFS - rx);
+ DBG ("%u/%u alloc/free buffers", rx, MAX_MEMIF_BUFS - rx);
err = memif_tx_burst (c->conn, qid, c->tx_bufs, j, &tx);
if (err != MEMIF_ERR_SUCCESS)
return 0;
error:
- err = memif_refill_queue (c->conn, qid, rx, 0);
+ err = memif_refill_queue (c->conn, qid, rx, ICMPR_HEADROOM);
if (err != MEMIF_ERR_SUCCESS)
INFO ("memif_buffer_free: %s", memif_strerror (err));
c->rx_buf_num -= rx;
DBG ("freed %d buffers. %u/%u alloc/free buffers",
- fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+ rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
return 0;
}
int err = MEMIF_ERR_SUCCESS, ret_val;
uint16_t rx = 0, tx = 0;
- uint16_t fb;
int i; /* rx buffer iterator */
int j; /* tx bufferiterator */
- int prev_i; /* first allocated rx buffer */
/* loop while there are packets in shm */
do
goto error;
}
- prev_i = i = 0;
+ i = 0;
/* loop while there are RX buffers to be processed */
while (rx)
}
/* mark memif buffers and shared memory buffers as free */
/* free processed buffers */
- err = memif_refill_queue (c->conn, qid, j, 0);
+ err = memif_refill_queue (c->conn, qid, j, ICMPR_HEADROOM);
if (err != MEMIF_ERR_SUCCESS)
INFO ("memif_buffer_free: %s", memif_strerror (err));
rx -= j;
- prev_i = i;
DBG ("freed %d buffers. %u/%u alloc/free buffers",
- fb, rx, MAX_MEMIF_BUFS - rx);
+ rx, rx, MAX_MEMIF_BUFS - rx);
/* transmit allocated buffers */
err = memif_tx_burst (c->conn, qid, c->tx_bufs, j, &tx);
return 0;
error:
- err = memif_refill_queue (c->conn, qid, rx, 0);
+ err = memif_refill_queue (c->conn, qid, rx, ICMPR_HEADROOM);
if (err != MEMIF_ERR_SUCCESS)
INFO ("memif_buffer_free: %s", memif_strerror (err));
c->rx_buf_num -= rx;
DBG ("freed %d buffers. %u/%u alloc/free buffers",
- fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+ rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
return 0;
}
int err = MEMIF_ERR_SUCCESS, ret_val;
int i;
uint16_t rx, tx;
- uint16_t fb;
- uint16_t pck_seq;
do
{
}
}
- err = memif_refill_queue (c->conn, qid, rx, 0);
+ err = memif_refill_queue (c->conn, qid, rx, ICMPR_HEADROOM);
if (err != MEMIF_ERR_SUCCESS)
INFO ("memif_buffer_free: %s", memif_strerror (err));
c->rx_buf_num -= rx;
return 0;
error:
- err = memif_refill_queue (c->conn, qid, rx, 0);
+ err = memif_refill_queue (c->conn, qid, rx, ICMPR_HEADROOM);
if (err != MEMIF_ERR_SUCCESS)
INFO ("memif_buffer_free: %s", memif_strerror (err));
c->rx_buf_num -= rx;
DBG ("freed %d buffers. %u/%u alloc/free buffers",
- fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+ rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
return 0;
}
/* setting memif connection arguments */
memif_conn_args_t args;
- int fd = -1;
memset (&args, 0, sizeof (args));
args.is_master = mode;
args.log2_ring_size = 11;
count -= tx;
}
timespec_get (&end, TIME_UTC);
+ printf ("\n\n");
INFO ("Pakcet sequence finished!");
INFO ("Seq len: %u", seq);
uint64_t t1 = end.tv_sec - start.tv_sec;
int
user_input_handler ()
{
- int i;
char *in = (char *) malloc (256);
char *ui = fgets (in, 256, stdin);
char *end;
int
poll_event (int timeout)
{
- struct epoll_event evt, *e;
+ struct epoll_event evt;
int app_err = 0, memif_err = 0, en = 0;
- int tmp, nfd;
uint32_t events = 0;
struct timespec start, end;
memset (&evt, 0, sizeof (evt));
/* if valid callback is passed as argument, fd event polling will be done by user
all file descriptors and events will be passed to user in this callback */
/* if callback is set to NULL libmemif will handle fd event polling */
- err = memif_init (control_fd_update, APP_NAME, NULL, NULL);
+ err = memif_init (control_fd_update, APP_NAME, NULL, NULL, NULL);
if (err != MEMIF_ERR_SUCCESS)
{
INFO ("memif_init: %s", memif_strerror (err));