|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
28 #include <sys/epoll.h>
29 #include <sys/eventfd.h>
35 #define APP_NAME "ICMP_Responder_mt_v3.1"
36 #define IF_NAME "memif_connection"
39 #define DBG(...) do { \
40 printf (APP_NAME":%s:%d: ", __func__, __LINE__); \
41 printf (__VA_ARGS__); \
48 #define ICMPR_BUFFER_LENGTH 32
49 #define ICMPR_SOCKET_FILENAME_LEN 256
50 #define ICMPR_MEMIF_BUFFER_NUM 256
53 {
"threads", required_argument, 0,
't'},
54 {
"if_num", required_argument, 0,
'i'}
93 DBG (
"invalid fd %d", fd);
96 struct epoll_event evt;
97 memset (&evt, 0,
sizeof (evt));
100 if (epoll_ctl (
epfd, EPOLL_CTL_ADD, fd, &evt) < 0)
102 DBG (
"epoll_ctl: %s fd %d", strerror (errno), fd);
105 DBG (
"fd %d added to epoll", fd);
114 DBG (
"invalid fd %d", fd);
117 struct epoll_event evt;
118 memset (&evt, 0,
sizeof (evt));
121 if (epoll_ctl (
epfd, EPOLL_CTL_MOD, fd, &evt) < 0)
123 DBG (
"epoll_ctl: %s fd %d", strerror (errno), fd);
126 DBG (
"fd %d modified on epoll", fd);
135 DBG (
"invalid fd %d", fd);
138 struct epoll_event evt;
139 memset (&evt, 0,
sizeof (evt));
140 if (epoll_ctl (
epfd, EPOLL_CTL_DEL, fd, &evt) < 0)
142 DBG (
"epoll_ctl: %s fd %d", strerror (errno), fd);
145 DBG (
"fd %d removed from epoll", fd);
186 DBG (
"Connected: %u",
c->id);
204 c->connected =
false;
205 DBG (
"Disconnected: %u",
c->id);
237 for (
i = 0;
i < rx;
i++)
274 struct epoll_event evt;
277 memset (&evt, 0,
sizeof (evt));
278 evt.events = EPOLLIN | EPOLLOUT;
280 en = epoll_pwait (
epfd, &evt, 1, timeout, NULL);
283 printf (
"epoll_pwait: %s\n", strerror (errno));
290 if (evt.data.fd == pcfd)
293 if (evt.events & EPOLLIN)
295 if (evt.events & EPOLLOUT)
297 if (evt.events & EPOLLERR)
316 ptd->
epfd = epoll_create (1);
319 if (ptd->
conns == NULL)
321 printf (
"%s\n", strerror (errno));
340 socket_filename[strlen (socket_filename)] =
'0' + ptd->
index;
341 strncpy (socket_filename + strlen (socket_filename),
".sock", 5);
342 DBG (
"socket_filename: %s", socket_filename);
345 socket_filename, ptd);
360 memset (&args, 0,
sizeof (args));
378 ptd->
pcfd = eventfd (0, EFD_NONBLOCK);
381 printf (
"eventfd: %s\n", strerror (errno));
386 printf (
"Failed to add poll cancel fd to epfd.");
417 (
"exit - Exits the application.\nhelp - Print this help.\nshow - Show memif interfaces\n");
427 printf (
"%u Threads %u Memifs (per thread)\n",
im->threads,
428 im->per_thread_if_num);
429 printf (
"=================================\n");
431 for (
i = 0;
i <
im->threads;
i++)
433 sh =
im->ptd[
i].socket_handle;
435 for (j = 0; j <
im->per_thread_if_num; j++)
437 printf (
"\tMemif id %u\n\t%s\n",
im->ptd[
i].conns[j].id,
438 im->ptd[
i].conns[j].connected ?
"Link up" :
"Link down");
448 int option_index = 0;
457 im->per_thread_if_num = 1;
461 getopt_long (argc, argv,
"t:i:",
options, &option_index)) != (-1))
466 im->threads = strtoul (optarg, NULL, 10);
469 im->per_thread_if_num = strtoul (optarg, NULL, 10);
479 printf (
"threads < 1\n");
483 if (
im->per_thread_if_num < 1)
485 printf (
"if_num < 1\n");
493 printf (
"%s\n", strerror (errno));
496 im->pthread =
malloc (
sizeof (pthread_t) *
im->threads);
497 if (
im->pthread == NULL)
499 printf (
"%s\n", strerror (errno));
504 for (
i = 0;
i <
im->threads;
i++)
506 im->ptd[
i].index =
i;
507 im->ptd[
i].if_num =
im->per_thread_if_num;
521 printf (
"%s\n", strerror (errno));
525 if (strncmp (
buffer,
"exit", 4) == 0)
527 else if (strncmp (
buffer,
"help", 4) == 0)
529 else if (strncmp (
buffer,
"show", 4) == 0)
533 for (
i = 0;
i <
im->threads;
i++)
536 rv = write (
im->ptd[
i].pcfd, &
b, sizeof (
b));
539 printf (
"Failed to cancel polling. %s\n", strerror (errno));
542 pthread_join (
im->pthread[
i], NULL);
#define MEMIF_FD_EVENT_MOD
update events
#define ICMPR_SOCKET_FILENAME_LEN
vnet_interface_main_t * im
int resolve_packet2(void *pck, uint32_t *size, uint8_t ip_addr[4])
int memif_per_thread_create_socket(memif_per_thread_main_handle_t pt_main, memif_socket_handle_t *sock, const char *filename, void *private_ctx)
Create memif socket.
#define MEMIF_FD_EVENT_WRITE
int on_connect(memif_conn_handle_t conn, void *private_ctx)
int control_fd_update(int fd, uint8_t events, void *ctx)
const char * memif_get_socket_filename(memif_socket_handle_t sock)
Get socket filename.
int memif_per_thread_cleanup(memif_per_thread_main_handle_t *pt_main)
Memif per thread cleanup.
int memif_create(memif_conn_handle_t *c, memif_conn_args_t *args, memif_connection_update_t *on_connect, memif_connection_update_t *on_disconnect, memif_interrupt_t *on_interrupt, void *private_ctx)
Memory interface create function.
Memif connection arguments.
int memif_buffer_enq_tx(memif_conn_handle_t conn, uint16_t qid, memif_buffer_t *bufs, uint16_t count, uint16_t *count_out)
Memif buffer enq tx.
void * memif_per_thread_main_handle_t
Memif per thread main handle Pointer of type void, pointing to internal structure.
int add_epoll_fd(int fd, uint32_t events)
int on_disconnect(memif_conn_handle_t conn, void *private_ctx)
int on_interrupt(memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
int memif_delete_socket(memif_socket_handle_t *sock)
Delete memif socket.
void * memif_socket_handle_t
Memif socket handle pointer of type void, pointing to internal structure.
int poll_event(int timeout)
int memif_per_thread_init(memif_per_thread_main_handle_t *pt_main, void *private_ctx, memif_control_fd_update_t *on_control_fd_update, char *app_name, memif_alloc_t *memif_alloc, memif_realloc_t *memif_realloc, memif_free_t *memif_free)
Memif per thread initialization.
static void icmpr_print_help()
struct per_thread_data * ptd
static perfmon_event_t events[]
struct memif_connection * conns
#define MEMIF_FD_EVENT_ERROR
inform libmemif that error occurred on fd
#define MEMIF_FD_EVENT_DEL
if set, informs that fd is going to be closed (user may want to stop watching for events on this fd)
memif_socket_handle_t socket
void * memif_conn_handle_t
Memif connection handle pointer of type void, pointing to internal structure.
int main(int argc, char *argv[])
int memif_tx_burst(memif_conn_handle_t conn, uint16_t qid, memif_buffer_t *bufs, uint16_t count, uint16_t *tx)
Memif transmit buffer burst.
memif_per_thread_main_handle_t pt_main
static struct option options[]
int memif_per_thread_control_fd_handler(memif_per_thread_main_handle_t pt_main, int fd, uint8_t events)
Memif per thread control file descriptor handler.
uint16_t per_thread_if_num
int memif_delete(memif_conn_handle_t *conn)
Memif delete.
static void * icmpr_thread_fn(void *data)
char * memif_strerror(int err_code)
Memif strerror.
void * malloc(size_t size)
static void icmpr_show_memifs()
struct per_thread_data * ptd
#define ICMPR_MEMIF_BUFFER_NUM
struct icmpr_main icmpr_main
memif_conn_handle_t handle
int memif_refill_queue(memif_conn_handle_t conn, uint16_t qid, uint16_t count, uint16_t headroom)
Memif refill queue.
#define MEMIF_FD_EVENT_READ
user needs to set events that occurred on fd and pass them to memif_control_fd_handler
int memif_rx_burst(memif_conn_handle_t conn, uint16_t qid, memif_buffer_t *bufs, uint16_t count, uint16_t *rx)
Memif receive buffer burst.
#define ICMPR_BUFFER_LENGTH
int mod_epoll_fd(int fd, uint32_t events)
memif_socket_handle_t socket_handle