FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
main.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <stdlib.h>
19 #include <stdint.h>
20 #include <net/if.h>
21 #include <sys/types.h>
22 #include <fcntl.h>
23 #include <sys/ioctl.h>
24 #include <sys/socket.h>
25 #include <sys/un.h>
26 #include <sys/uio.h>
27 #include <sys/mman.h>
28 #include <sys/prctl.h>
29 #include <inttypes.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <netdb.h>
33 #include <linux/ip.h>
34 #include <linux/icmp.h>
35 #include <arpa/inet.h>
36 #include <stdlib.h>
37 #include <netinet/if_ether.h>
38 #include <net/if_arp.h>
39 #include <asm/byteorder.h>
40 #include <byteswap.h>
41 #include <string.h>
42 #include <sys/epoll.h>
43 #include <errno.h>
44 #include <unistd.h>
45 #include <signal.h>
46 
47 #include <time.h>
48 
49 #include <libmemif.h>
50 #include <icmp_proto.h>
51 
52 #define APP_NAME "ICMP_Responder"
53 #define IF_NAME "memif_connection"
54 
55 #define HEADROOM 0x80 /* 128b */
56 #define ENCAP 0x60
57 
58 #ifdef ICMP_DBG
59 #define DBG(...) do { \
60  printf (APP_NAME":%s:%d: ", __func__, __LINE__); \
61  printf (__VA_ARGS__); \
62  printf ("\n"); \
63  } while (0)
64 #define LOG(...) do { \
65  if (enable_log) { \
66  dprintf (out_fd, __VA_ARGS__); \
67  dprintf (out_fd, "\n"); \
68  } \
69  } while (0)
70 #define LOG_FILE "/tmp/memif_time_test.txt"
71 #else
72 #define DBG(...)
73 #define LOG(...)
74 #endif
75 
76 #define INFO(...) do { \
77  printf ("INFO: "__VA_ARGS__); \
78  printf ("\n"); \
79  } while (0)
80 
81 
82 /* maximum tx/rx memif buffers */
83 #define MAX_MEMIF_BUFS 256
84 #define MAX_CONNS 50
85 
86 int epfd;
87 int out_fd;
88 uint8_t enable_log;
89 
90 typedef struct
91 {
92  uint16_t index;
93  /* memif connection handle */
95  /* buffers */
97  /* allocated tx buffers counter */
98  /* number of tx buffers pointing to shared memory */
99  uint16_t tx_buf_num;
100  /* allocated rx buffers counter */
101  /* number of rx buffers pointing to shared memory */
102  uint16_t rx_buf_num;
103  /* interface ip address */
104  uint8_t ip_addr[4];
105  uint64_t tx_counter, rx_counter, tx_err_counter;
106  uint64_t t_sec, t_nsec;
108 
109 typedef struct
110 {
111  uint16_t index;
113  uint64_t packet_count;
114  uint16_t sequence;
115  uint64_t tx;
116  uint8_t ip_daddr[4];
117  uint8_t hw_daddr[6];
118  struct timespec *start, end;
119 } icmpr_flow_t;
120 
124 
125 /* print details for all memif connections */
126 static void
128 {
129  memif_details_t md;
130  ssize_t buflen;
131  char *buf;
132  int err, i, e;
133  buflen = 2048;
134  buf = malloc (buflen);
135  printf ("MEMIF DETAILS\n");
136  printf ("==============================\n");
137  for (i = 0; i < MAX_CONNS; i++)
138  {
140 
141  memset (&md, 0, sizeof (md));
142  memset (buf, 0, buflen);
143 
144  err = memif_get_details (c->conn, &md, buf, buflen);
145  if (err != MEMIF_ERR_SUCCESS)
146  {
147  if (err != MEMIF_ERR_NOCONN)
148  INFO ("%s", memif_strerror (err));
149  continue;
150  }
151 
152  printf ("interface index: %d\n", i);
153 
154  printf ("\tinterface ip: %u.%u.%u.%u\n",
155  c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
156  printf ("\tinterface name: %s\n", (char *) md.if_name);
157  printf ("\tapp name: %s\n", (char *) md.inst_name);
158  printf ("\tremote interface name: %s\n", (char *) md.remote_if_name);
159  printf ("\tremote app name: %s\n", (char *) md.remote_inst_name);
160  printf ("\tid: %u\n", md.id);
161  printf ("\tsecret: %s\n", (char *) md.secret);
162  printf ("\trole: ");
163  if (md.role)
164  printf ("slave\n");
165  else
166  printf ("master\n");
167  printf ("\tmode: ");
168  switch (md.mode)
169  {
170  case 0:
171  printf ("ethernet\n");
172  break;
173  case 1:
174  printf ("ip\n");
175  break;
176  case 2:
177  printf ("punt/inject\n");
178  break;
179  default:
180  printf ("unknown\n");
181  break;
182  }
183  printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
184  printf ("\trx queues:\n");
185  for (e = 0; e < md.rx_queues_num; e++)
186  {
187  printf ("\t\tqueue id: %u\n", md.rx_queues[e].qid);
188  printf ("\t\tring size: %u\n", md.rx_queues[e].ring_size);
189  printf ("\t\tring rx mode: %s\n",
190  md.rx_queues[e].flags ? "polling" : "interrupt");
191  printf ("\t\tring head: %u\n", md.rx_queues[e].head);
192  printf ("\t\tring tail: %u\n", md.rx_queues[e].tail);
193  printf ("\t\tbuffer size: %u\n", md.rx_queues[e].buffer_size);
194  }
195  printf ("\ttx queues:\n");
196  for (e = 0; e < md.tx_queues_num; e++)
197  {
198  printf ("\t\tqueue id: %u\n", md.tx_queues[e].qid);
199  printf ("\t\tring size: %u\n", md.tx_queues[e].ring_size);
200  printf ("\t\tring rx mode: %s\n",
201  md.tx_queues[e].flags ? "polling" : "interrupt");
202  printf ("\t\tring head: %u\n", md.tx_queues[e].head);
203  printf ("\t\tring tail: %u\n", md.tx_queues[e].tail);
204  printf ("\t\tbuffer size: %u\n", md.tx_queues[e].buffer_size);
205  }
206  printf ("\tlink: ");
207  if (md.link_up_down)
208  printf ("up\n");
209  else
210  printf ("down\n");
211  }
212  free (buf);
213 }
214 
215 int
216 add_epoll_fd (int fd, uint32_t events)
217 {
218  if (fd < 0)
219  {
220  DBG ("invalid fd %d", fd);
221  return -1;
222  }
223  struct epoll_event evt;
224  memset (&evt, 0, sizeof (evt));
225  evt.events = events;
226  evt.data.fd = fd;
227  if (epoll_ctl (epfd, EPOLL_CTL_ADD, fd, &evt) < 0)
228  {
229  DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
230  return -1;
231  }
232  DBG ("fd %d added to epoll", fd);
233  return 0;
234 }
235 
236 int
237 mod_epoll_fd (int fd, uint32_t events)
238 {
239  if (fd < 0)
240  {
241  DBG ("invalid fd %d", fd);
242  return -1;
243  }
244  struct epoll_event evt;
245  memset (&evt, 0, sizeof (evt));
246  evt.events = events;
247  evt.data.fd = fd;
248  if (epoll_ctl (epfd, EPOLL_CTL_MOD, fd, &evt) < 0)
249  {
250  DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
251  return -1;
252  }
253  DBG ("fd %d modified on epoll", fd);
254  return 0;
255 }
256 
257 int
258 del_epoll_fd (int fd)
259 {
260  if (fd < 0)
261  {
262  DBG ("invalid fd %d", fd);
263  return -1;
264  }
265  struct epoll_event evt;
266  memset (&evt, 0, sizeof (evt));
267  if (epoll_ctl (epfd, EPOLL_CTL_DEL, fd, &evt) < 0)
268  {
269  DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
270  return -1;
271  }
272  DBG ("fd %d removed from epoll", fd);
273  return 0;
274 }
275 
276 /* informs user about connected status. private_ctx is used by user to identify connection
277  (multiple connections WIP) */
278 int
279 on_connect (memif_conn_handle_t conn, void *private_ctx)
280 {
281  INFO ("memif connected!");
282  memif_refill_queue (conn, 0, -1, HEADROOM);
283  enable_log = 1;
284  return 0;
285 }
286 
287 /* informs user about disconnected status. private_ctx is used by user to identify connection
288  (multiple connections WIP) */
289 int
290 on_disconnect (memif_conn_handle_t conn, void *private_ctx)
291 {
292  INFO ("memif disconnected!");
293  return 0;
294 }
295 
296 /* user needs to watch new fd or stop watching fd that is about to be closed.
297  control fd will be modified during connection establishment to minimize CPU usage */
298 int
299 control_fd_update (int fd, uint8_t events, void *ctx)
300 {
301  /* convert memif event definitions to epoll events */
303  return del_epoll_fd (fd);
304 
305  uint32_t evt = 0;
307  evt |= EPOLLIN;
309  evt |= EPOLLOUT;
310 
312  return mod_epoll_fd (fd, evt);
313 
314  return add_epoll_fd (fd, evt);
315 }
316 
317 /* called when event is polled on interrupt file descriptor.
318  there are packets in shared memory ready to be received */
319 /* handle packet processing in rx buffer then enqueue this buffer to tx and transmit */
320 int
321 on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
322 {
323  long index = *((long *) private_ctx);
325  if (c->index != index)
326  {
327  INFO ("invalid context: %ld/%u", index, c->index);
328  return 0;
329  }
330 
331  int err = MEMIF_ERR_SUCCESS, ret_val;
332  uint16_t rx = 0, tx = 0;
333  int i = 0; /* rx buffer iterator */
334 
335  /* loop while there are packets in shm */
336  do
337  {
338  /* receive data from shared memory buffers (dequeue rx buffers) */
339  err = memif_rx_burst (c->conn, qid, c->bufs, MAX_MEMIF_BUFS, &rx);
340  ret_val = err;
341  c->rx_counter += rx;
342  c->rx_buf_num += rx;
343  if ((err != MEMIF_ERR_SUCCESS) && (err != MEMIF_ERR_NOBUF))
344  {
345  INFO ("memif_rx_burst: %s", memif_strerror (err));
346  goto error;
347  }
348 
349  /* process buffers in place */
350  for (i = 0; i < rx; i++)
351  {
352  resolve_packet2 ((void *) (c->bufs + i)->data,
353  &(c->bufs + i)->len, c->ip_addr);
354  }
355 
356  /* enqueue processed buffers to tx ring */
357  err = memif_buffer_enq_tx (c->conn, qid, c->bufs, i, &tx);
358  if ((err != MEMIF_ERR_SUCCESS) && (err != MEMIF_ERR_NOBUF_RING))
359  {
360  INFO ("memif_buffer_alloc: %s", memif_strerror (err));
361  goto error;
362  }
363  c->rx_buf_num -= tx;
364  c->tx_buf_num += tx;
365  c->tx_err_counter += i - tx;
366 
367  /* mark memif buffers and shared memory buffers as free */
368  err = memif_refill_queue (c->conn, qid, rx, HEADROOM);
369  if (err != MEMIF_ERR_SUCCESS)
370  INFO ("memif_buffer_free: %s", memif_strerror (err));
371  c->rx_buf_num -= rx;
372 
373  DBG ("freed %d buffers. %u/%u alloc/free buffers",
374  rx, rx, MAX_MEMIF_BUFS - rx);
375 
376  /* transmit allocated buffers */
377  err = memif_tx_burst (c->conn, qid, c->bufs, rx, &tx);
378  if (err != MEMIF_ERR_SUCCESS)
379  {
380  INFO ("memif_tx_burst: %s", memif_strerror (err));
381  goto error;
382  }
383  c->tx_counter += tx;
384 
385  }
386  while (ret_val == MEMIF_ERR_NOBUF);
387 
388  return 0;
389 
390 error:
391  err = memif_refill_queue (c->conn, qid, -1, HEADROOM);
392  if (err != MEMIF_ERR_SUCCESS)
393  INFO ("memif_buffer_free: %s", memif_strerror (err));
394  c->rx_buf_num = 0;
395  DBG ("freed %d buffers. %u/%u alloc/free buffers",
396  rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
397  return 0;
398 }
399 
400 /* add ethernet encap to packet in rx buffer then enqueue this buffer to tx and transmit */
401 int
402 on_interrupt0 (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
403 {
404  long index = *((long *) private_ctx);
406  if (c->index != index)
407  {
408  INFO ("invalid context: %ld/%u", index, c->index);
409  return 0;
410  }
411 
412  int err = MEMIF_ERR_SUCCESS, ret_val;
413  uint16_t rx = 0, tx = 0;
414  int i = 0; /* rx buffer iterator */
415 
416  /* loop while there are packets in shm */
417  do
418  {
419  /* receive data from shared memory buffers (dequeue rx buffers) */
420  err = memif_rx_burst (c->conn, qid, c->bufs, MAX_MEMIF_BUFS, &rx);
421  ret_val = err;
422  c->rx_counter += rx;
423  c->rx_buf_num += rx;
424  if ((err != MEMIF_ERR_SUCCESS) && (err != MEMIF_ERR_NOBUF))
425  {
426  INFO ("memif_rx_burst: %s", memif_strerror (err));
427  goto error;
428  }
429 
430  /* process bufers in place */
431  for (i = 0; i < rx; i++)
432  {
433  resolve_packet3 (&c->bufs[i].data, &c->bufs[i].len, c->ip_addr);
434  }
435  /* enque processed buffers to tx ring */
436  err = memif_buffer_enq_tx (c->conn, qid, c->bufs, rx, &tx);
437  if ((err != MEMIF_ERR_SUCCESS) && (err != MEMIF_ERR_NOBUF_RING))
438  {
439  INFO ("memif_buffer_alloc: %s", memif_strerror (err));
440  goto error;
441  }
442  c->rx_buf_num -= tx;
443  c->tx_buf_num += tx;
444  c->tx_err_counter += i - tx;
445 
446  /* mark memif buffers and shared memory buffers as free */
447  err = memif_refill_queue (c->conn, qid, rx, HEADROOM);
448  if (err != MEMIF_ERR_SUCCESS)
449  INFO ("memif_buffer_free: %s", memif_strerror (err));
450  c->rx_buf_num -= rx;
451 
452  DBG ("freed %d buffers. %u/%u alloc/free buffers",
453  rx, rx, MAX_MEMIF_BUFS - rx);
454 
455  /* transmit allocated buffers */
456  err = memif_tx_burst (c->conn, qid, c->bufs, i, &tx);
457  if (err != MEMIF_ERR_SUCCESS)
458  {
459  INFO ("memif_tx_burst: %s", memif_strerror (err));
460  goto error;
461  }
462  c->tx_counter += tx;
463 
464  }
465  while (ret_val == MEMIF_ERR_NOBUF);
466 
467  return 0;
468 
469 error:
470  err = memif_refill_queue (c->conn, qid, -1, HEADROOM);
471  if (err != MEMIF_ERR_SUCCESS)
472  INFO ("memif_buffer_free: %s", memif_strerror (err));
473  c->rx_buf_num = 0;
474  DBG ("freed %d buffers. %u/%u alloc/free buffers",
475  rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
476  return 0;
477 }
478 
479 /* called when event is polled on interrupt file descriptor.
480  there are packets in shared memory ready to be received */
481 /* dev test modification: handle only ARP requests */
482 int
483 on_interrupt1 (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
484 {
485  long index = *((long *) private_ctx);
487  if (c->index != index)
488  {
489  INFO ("invalid context: %ld/%u", index, c->index);
490  return 0;
491  }
492 
493  int err = MEMIF_ERR_SUCCESS, ret_val;
494  int i;
495  uint16_t rx, tx;
496 
497  do
498  {
499  /* receive data from shared memory buffers */
500  err = memif_rx_burst (c->conn, qid, c->bufs, MAX_MEMIF_BUFS, &rx);
501  ret_val = err;
502  c->rx_buf_num += rx;
503  c->rx_counter += rx;
504  if ((err != MEMIF_ERR_SUCCESS) && (err != MEMIF_ERR_NOBUF))
505  {
506  INFO ("memif_rx_burst: %s", memif_strerror (err));
507  goto error;
508  }
509 
510  for (i = 0; i < rx; i++)
511  {
512  if (((struct ether_header *) (c->bufs + i)->data)->ether_type ==
513  0x0608)
514  {
515  /* process data in place */
516  resolve_packet2 ((void *) (c->bufs + i)->data,
517  &(c->bufs + i)->len, c->ip_addr);
518  /* enque buffer to tx ring */
519  memif_buffer_enq_tx (c->conn, qid, c->bufs, 1, &tx);
520  c->rx_buf_num -= tx;
521  memif_tx_burst (c->conn, qid, c->bufs, 1, &tx);
522  }
523  }
524 
525  err = memif_refill_queue (c->conn, qid, -1, HEADROOM);
526  if (err != MEMIF_ERR_SUCCESS)
527  INFO ("memif_buffer_free: %s", memif_strerror (err));
528  c->rx_buf_num -= rx;
529 
530  }
531  while (ret_val == MEMIF_ERR_NOBUF);
532 
533  return 0;
534 
535 error:
536  err = memif_refill_queue (c->conn, qid, -1, HEADROOM);
537  if (err != MEMIF_ERR_SUCCESS)
538  INFO ("memif_buffer_free: %s", memif_strerror (err));
539  c->rx_buf_num = 0;
540  DBG ("freed %d buffers. %u/%u alloc/free buffers",
541  rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
542  return 0;
543 }
544 
545 int
546 icmpr_memif_create (long index, long mode, char *s)
547 {
548  if (index >= MAX_CONNS)
549  {
550  INFO ("connection array overflow");
551  return 0;
552  }
553  if (index < 0)
554  {
555  INFO ("don't even try...");
556  return 0;
557  }
559 
560  /* setting memif connection arguments */
561  memif_conn_args_t args;
562  memset (&args, 0, sizeof (args));
563  args.is_master = mode;
564  args.log2_ring_size = 11;
565  args.buffer_size = 2048;
566  args.num_s2m_rings = 1;
567  args.num_m2s_rings = 1;
568  strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
569  args.mode = 0;
570  /* socket filename is not specified, because this app is supposed to
571  connect to VPP over memif. so default socket filename will be used */
572  /* default socketfile = /run/vpp/memif.sock */
573 
574  args.interface_id = index;
575  /* last argument for memif_create (void * private_ctx) is used by user
576  to identify connection. this context is returned with callbacks */
577  int err;
578  /* default interrupt */
579  if (s == NULL)
580  {
581  err = memif_create (&c->conn,
583  &ctx[index]);
584  if (err != MEMIF_ERR_SUCCESS)
585  {
586  INFO ("memif_create: %s", memif_strerror (err));
587  return 0;
588  }
589  }
590  else
591  {
592  if (strncmp (s, "0", 1) == 0)
593  {
594  err = memif_create (&c->conn,
596  &ctx[index]);
597  if (err != MEMIF_ERR_SUCCESS)
598  {
599  INFO ("memif_create: %s", memif_strerror (err));
600  return 0;
601  }
602  }
603  else if (strncmp (s, "1", 1) == 0)
604  {
605  err = memif_create (&c->conn,
607  &ctx[index]);
608  if (err != MEMIF_ERR_SUCCESS)
609  {
610  INFO ("memif_create: %s", memif_strerror (err));
611  return 0;
612  }
613  }
614  else
615  {
616  INFO ("Unknown interrupt descriptor");
617  goto done;
618  }
619  }
620 
621  c->index = index;
622  /* alloc memif buffers */
623  c->rx_buf_num = 0;
624  c->tx_buf_num = 0;
625  c->bufs =
627 
628  c->ip_addr[0] = 192;
629  c->ip_addr[1] = 168;
630  c->ip_addr[2] = c->index + 1;
631  c->ip_addr[3] = 2;
632 
633  c->tx_err_counter = c->tx_counter = c->rx_counter = 0;
634 
635 done:
636  return 0;
637 }
638 
639 int
641 {
642  if (index >= MAX_CONNS)
643  {
644  INFO ("connection array overflow");
645  return 0;
646  }
647  if (index < 0)
648  {
649  INFO ("don't even try...");
650  return 0;
651  }
653 
654  if (c->bufs)
655  free (c->bufs);
656  c->bufs = NULL;
657  c->tx_buf_num = 0;
658  c->rx_buf_num = 0;
659 
660  int err;
661  /* disconnect then delete memif connection */
662  err = memif_delete (&c->conn);
663  if (err != MEMIF_ERR_SUCCESS)
664  INFO ("memif_delete: %s", memif_strerror (err));
665  if (c->conn != NULL)
666  INFO ("memif delete fail");
667  return 0;
668 }
669 
670 void
672 {
673  printf ("LIBMEMIF EXAMPLE APP: %s", APP_NAME);
674 #ifdef ICMP_DBG
675  printf (" (debug)");
676 #endif
677  printf ("\n");
678  printf ("==============================\n");
679  printf ("libmemif version: %s", LIBMEMIF_VERSION);
680 #ifdef MEMIF_DBG
681  printf (" (debug)");
682 #endif
683  printf ("\n");
684  printf ("memif version: %d\n", memif_get_version ());
685  printf ("commands:\n");
686  printf ("\thelp - prints this help\n");
687  printf ("\texit - exit app\n");
688  printf
689  ("\tconn <index> <mode> [<interrupt-desc>] - create memif. index is also used as interface id, mode 0 = slave 1 = master, interrupt-desc none = default 0 = if ring is full wait 1 = handle only ARP requests\n");
690  printf ("\tdel <index> - delete memif\n");
691  printf ("\tshow - show connection details\n");
692  printf ("\tip-set <index> <ip-addr> - set interface ip address\n");
693  printf
694  ("\trx-mode <index> <qid> <polling|interrupt> - set queue rx mode\n");
695  printf ("\tsh-count - print counters\n");
696  printf ("\tcl-count - clear counters\n");
697  printf
698  ("\tsend <index> <tx> <ip> <mac> - send icmp, ommit mac to transmit on ip layer\n");
699 }
700 
701 int
703 {
704  /* application cleanup */
705  int err;
706  long i;
707  if (out_fd > 0)
708  close (out_fd);
709  out_fd = -1;
710  for (i = 0; i < MAX_CONNS; i++)
711  {
713  if (c->conn)
715  }
716 
717  err = memif_cleanup ();
718  if (err != MEMIF_ERR_SUCCESS)
719  INFO ("memif_delete: %s", memif_strerror (err));
720 
721  return 0;
722 }
723 
724 int
725 icmpr_set_ip (long index, char *ip)
726 {
727  if (index >= MAX_CONNS)
728  {
729  INFO ("connection array overflow");
730  return 0;
731  }
732  if (index < 0)
733  {
734  INFO ("don't even try...");
735  return 0;
736  }
738  if (c->conn == NULL)
739  {
740  INFO ("no connection at index %ld", index);
741  return 0;
742  }
743 
744  char *end;
745  char *ui;
746  uint8_t tmp[4];
747  ui = strtok (ip, ".");
748  if (ui == NULL)
749  goto error;
750  tmp[0] = strtol (ui, &end, 10);
751 
752  ui = strtok (NULL, ".");
753  if (ui == NULL)
754  goto error;
755  tmp[1] = strtol (ui, &end, 10);
756 
757  ui = strtok (NULL, ".");
758  if (ui == NULL)
759  goto error;
760  tmp[2] = strtol (ui, &end, 10);
761 
762  ui = strtok (NULL, ".");
763  if (ui == NULL)
764  goto error;
765  tmp[3] = strtol (ui, &end, 10);
766 
767  c->ip_addr[0] = tmp[0];
768  c->ip_addr[1] = tmp[1];
769  c->ip_addr[2] = tmp[2];
770  c->ip_addr[3] = tmp[3];
771 
772  INFO ("memif %ld ip address set to %u.%u.%u.%u",
773  index, c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
774 
775  return 0;
776 
777 error:
778  INFO ("invalid ip address");
779  return 0;
780 }
781 
782 int
783 icmpr_set_rx_mode (long index, long qid, char *mode)
784 {
785  if (index >= MAX_CONNS)
786  {
787  INFO ("connection array overflow");
788  return 0;
789  }
790  if (index < 0)
791  {
792  INFO ("don't even try...");
793  return 0;
794  }
796 
797  if (c->conn == NULL)
798  {
799  INFO ("no connection at index %ld", index);
800  return 0;
801  }
802 
803  if (strncmp (mode, "interrupt", 9) == 0)
804  {
806  }
807 
808  else if (strncmp (mode, "polling", 7) == 0)
809  {
811  }
812  else
813  INFO ("expected rx mode <interrupt|polling>");
814  return 0;
815 }
816 
817 void
819 {
820  int i;
821  for (i = 0; i < MAX_CONNS; i++)
822  {
824  if (c->conn == NULL)
825  continue;
826  printf ("===============================\n");
827  printf ("interface index: %d\n", c->index);
828  printf ("\trx: %lu\n", c->rx_counter);
829  printf ("\ttx: %lu\n", c->tx_counter);
830  printf ("\ttx_err: %lu\n", c->tx_err_counter);
831  printf ("\tts: %lus %luns\n", c->t_sec, c->t_nsec);
832  }
833 }
834 
835 void
837 {
838  int i;
839  for (i = 0; i < MAX_CONNS; i++)
840  {
842  if (c->conn == NULL)
843  continue;
844  c->t_sec = c->t_nsec = c->tx_err_counter = c->tx_counter =
845  c->rx_counter = 0;
846  }
847 }
848 
849 void
851 {
853  if (c->conn == NULL)
854  {
855  INFO ("No connection at index %d. Stopping flow...\n", flow->index);
856  goto stop_flow;
857  }
858  uint16_t tx, i;
859  int err = MEMIF_ERR_SUCCESS;
860 
861  if (!flow->start)
862  {
863  flow->start = malloc (sizeof (struct timespec));
864  memset (flow->start, 0, sizeof (struct timespec));
865  timespec_get (flow->start, TIME_UTC);
866  }
867 
868  i = 0;
869  err = memif_buffer_alloc (c->conn, 0, c->bufs,
871  flow->packet_count ? flow->packet_count :
872  MAX_MEMIF_BUFS, &tx, 64);
873  if ((err != MEMIF_ERR_SUCCESS) && (err != MEMIF_ERR_NOBUF_RING))
874  {
875  INFO ("memif_buffer_alloc: %s Stopping flow...\n",
876  memif_strerror (err));
877  goto stop_flow;
878  }
879  c->tx_buf_num += tx;
880 
881  while (tx)
882  {
883  generate_packet2 ((void *) c->bufs[i].data,
884  &c->bufs[i].len, c->ip_addr,
885  flow->ip_daddr, flow->hw_daddr, (flow->sequence)++,
886  flow->mode);
887  i++;
888  tx--;
889  }
890  err = memif_tx_burst (c->conn, 0, c->bufs, i, &tx);
891  if (err != MEMIF_ERR_SUCCESS)
892  {
893  INFO ("memif_tx_burst: %s Stopping flow...\n", memif_strerror (err));
894  goto stop_flow;
895  }
896  c->tx_buf_num -= tx;
897  c->tx_counter += tx;
898  flow->tx += tx;
899  flow->packet_count -= tx;
900 
901  if (flow->packet_count == 0)
902  {
903  timespec_get (&flow->end, TIME_UTC);
904  INFO ("Flow finished!");
905  INFO ("Flow length: %lu", flow->tx);
906  uint64_t t1 = flow->end.tv_sec - flow->start->tv_sec;
907  uint64_t t2;
908  if (flow->end.tv_nsec > flow->start->tv_nsec)
909  {
910  t2 = flow->end.tv_nsec - flow->start->tv_nsec;
911  }
912  else
913  {
914  t2 = flow->start->tv_nsec - flow->end.tv_nsec;
915  t1--;
916  }
917  c->t_sec = t1;
918  c->t_nsec = t2;
919  INFO ("Flow time: %lus %luns", t1, t2);
920  double tmp = t1;
921  tmp += t2 / 1e+9;
922  tmp = flow->tx / tmp;
923  INFO ("Average pps: %f", tmp);
924  INFO ("Stopping flow...");
925  goto stop_flow;
926  }
927 
928  return;
929 
930 stop_flow:
931  if (flow)
932  {
933  if (flow->start)
934  free (flow->start);
935  free (flow);
936  }
937  flow = NULL;
938  return;
939 }
940 
941 int
942 icmpr_send (long index, long packet_num, char *input)
943 {
944  if (flow)
945  {
946  printf ("only one flow allowed\n");
947  return 0;
948  }
949 
951  char *end;
952  char *ui;
953  uint8_t tmp[6];
954  if (c->conn == NULL)
955  return -1;
956 
957  flow = malloc (sizeof (icmpr_flow_t));
958  flow->index = index;
959  flow->packet_count = packet_num;
960  flow->sequence = 0;
961  flow->tx = 0;
962  flow->start = NULL;
963  memset (&flow->end, 0, sizeof (struct timespec));
964 
965  INFO ("packet count: %lu", flow->packet_count);
966  printf ("%s\n", input);
967 
968  ui = strtok (input, ".");
969  if (ui == NULL)
970  goto error;
971  tmp[0] = strtol (ui, &end, 10);
972 
973  ui = strtok (NULL, ".");
974  if (ui == NULL)
975  goto error;
976  tmp[1] = strtol (ui, &end, 10);
977 
978  ui = strtok (NULL, ".");
979  if (ui == NULL)
980  goto error;
981  tmp[2] = strtol (ui, &end, 10);
982 
983  ui = strtok (NULL, ".");
984  if (ui == NULL)
985  goto error;
986  tmp[3] = strtol (ui, &end, 10);
987 
988  flow->ip_daddr[0] = tmp[0];
989  flow->ip_daddr[1] = tmp[1];
990  flow->ip_daddr[2] = tmp[2];
991  flow->ip_daddr[3] = tmp[3];
992 
993  ui = strtok (NULL, " ");
994  if (ui == NULL)
995  {
996  flow->mode = ICMPR_FLOW_MODE_IP;
997  return 0;
998  }
999 
1000  ui = strtok (NULL, ":");
1001  if (ui == NULL)
1002  goto error;
1003  tmp[0] = strtol (ui, &end, 16);
1004  ui = strtok (NULL, ":");
1005  if (ui == NULL)
1006  goto error;
1007  tmp[1] = strtol (ui, &end, 16);
1008  ui = strtok (NULL, ":");
1009  if (ui == NULL)
1010  goto error;
1011  tmp[2] = strtol (ui, &end, 16);
1012  ui = strtok (NULL, ":");
1013  if (ui == NULL)
1014  goto error;
1015  tmp[3] = strtol (ui, &end, 16);
1016  ui = strtok (NULL, ":");
1017  if (ui == NULL)
1018  goto error;
1019  tmp[4] = strtol (ui, &end, 16);
1020  ui = strtok (NULL, ":");
1021  if (ui == NULL)
1022  goto error;
1023  tmp[5] = strtol (ui, &end, 16);
1024 
1025  flow->hw_daddr[0] = tmp[0];
1026  flow->hw_daddr[1] = tmp[1];
1027  flow->hw_daddr[2] = tmp[2];
1028  flow->hw_daddr[3] = tmp[3];
1029  flow->hw_daddr[4] = tmp[4];
1030  flow->hw_daddr[5] = tmp[5];
1031 
1032  flow->mode = ICMPR_FLOW_MODE_ETH;
1033 
1034  return 0;
1035 
1036 error:
1037  INFO ("Invalid input\n");
1038  if (flow)
1039  free (flow);
1040  flow = NULL;
1041  return 0;
1042 }
1043 
1044 int
1046 {
1047  char *in = (char *) malloc (256);
1048  char *ui = fgets (in, 256, stdin);
1049  char *end;
1050  long a;
1051  if (in[0] == '\n')
1052  goto done;
1053  ui = strtok (in, " ");
1054  if (strncmp (ui, "exit", 4) == 0)
1055  {
1056  free (in);
1057  icmpr_free ();
1058  exit (EXIT_SUCCESS);
1059  }
1060  else if (strncmp (ui, "help", 4) == 0)
1061  {
1062  print_help ();
1063  goto done;
1064  }
1065  else if (strncmp (ui, "conn", 4) == 0)
1066  {
1067  ui = strtok (NULL, " ");
1068  if (ui != NULL)
1069  a = strtol (ui, &end, 10);
1070  else
1071  {
1072  INFO ("expected id");
1073  goto done;
1074  }
1075  ui = strtok (NULL, " ");
1076  if (ui != NULL)
1077  icmpr_memif_create (a, strtol (ui, &end, 10), strtok (NULL, " "));
1078  else
1079  INFO ("expected mode <0|1>");
1080  goto done;
1081  }
1082  else if (strncmp (ui, "del", 3) == 0)
1083  {
1084  ui = strtok (NULL, " ");
1085  if (ui != NULL)
1086  icmpr_memif_delete (strtol (ui, &end, 10));
1087  else
1088  INFO ("expected id");
1089  goto done;
1090  }
1091  else if (strncmp (ui, "show", 4) == 0)
1092  {
1094  goto done;
1095  }
1096  else if (strncmp (ui, "ip-set", 6) == 0)
1097  {
1098  ui = strtok (NULL, " ");
1099  if (ui != NULL)
1100  icmpr_set_ip (strtol (ui, &end, 10), strtok (NULL, " "));
1101  else
1102  INFO ("expected id");
1103  goto done;
1104  }
1105  else if (strncmp (ui, "rx-mode", 7) == 0)
1106  {
1107  ui = strtok (NULL, " ");
1108  if (ui != NULL)
1109  a = strtol (ui, &end, 10);
1110  else
1111  {
1112  INFO ("expected id");
1113  goto done;
1114  }
1115  ui = strtok (NULL, " ");
1116  if (ui != NULL)
1117  icmpr_set_rx_mode (a, strtol (ui, &end, 10), strtok (NULL, " "));
1118  else
1119  INFO ("expected qid");
1120  goto done;
1121  }
1122  else if (strncmp (ui, "sh-count", 8) == 0)
1123  {
1125  }
1126  else if (strncmp (ui, "cl-count", 8) == 0)
1127  {
1129  }
1130  else if (strncmp (ui, "send", 4) == 0)
1131  {
1132  ui = strtok (NULL, " ");
1133  if (ui != NULL)
1134  a = strtol (ui, &end, 10);
1135  else
1136  {
1137  INFO ("expected id");
1138  goto done;
1139  }
1140  ui = strtok (NULL, " ");
1141  if (ui != NULL)
1142  icmpr_send (a, strtol (ui, &end, 10), strtok (NULL, " "));
1143  else
1144  INFO ("expected count");
1145  goto done;
1146  }
1147  else
1148  {
1149  INFO ("unknown command: %s", ui);
1150  goto done;
1151  }
1152 
1153  return 0;
1154 done:
1155  free (in);
1156  return 0;
1157 }
1158 
1159 int
1160 poll_event (int timeout)
1161 {
1162  struct epoll_event evt;
1163  int app_err = 0, memif_err = 0, en = 0;
1164  uint32_t events = 0;
1165  struct timespec start, end;
1166  memset (&evt, 0, sizeof (evt));
1167  evt.events = EPOLLIN | EPOLLOUT;
1168  sigset_t sigset;
1169  sigemptyset (&sigset);
1170  en = epoll_pwait (epfd, &evt, 1, timeout, &sigset);
1171  /* id event polled */
1172  timespec_get (&start, TIME_UTC);
1173  if (en < 0)
1174  {
1175  DBG ("epoll_pwait: %s", strerror (errno));
1176  return -1;
1177  }
1178  if (en > 0)
1179  {
1180  /* this app does not use any other file descriptors than stds and memif control fds */
1181  if (evt.data.fd > 2)
1182  {
1183  /* event of memif control fd */
1184  /* convert epoll events to memif events */
1185  if (evt.events & EPOLLIN)
1187  if (evt.events & EPOLLOUT)
1189  if (evt.events & EPOLLERR)
1191  memif_err = memif_control_fd_handler (evt.data.fd, events);
1192  if (memif_err != MEMIF_ERR_SUCCESS)
1193  INFO ("memif_control_fd_handler: %s", memif_strerror (memif_err));
1194  }
1195  else if (evt.data.fd == 0)
1196  {
1197  app_err = user_input_handler ();
1198  }
1199  else
1200  {
1201  DBG ("unexpected event at memif_epfd. fd %d", evt.data.fd);
1202  }
1203  }
1204 
1205  timespec_get (&end, TIME_UTC);
1206  LOG ("interrupt: %ld", end.tv_nsec - start.tv_nsec);
1207 
1208  if ((app_err < 0) || (memif_err < 0))
1209  {
1210  if (app_err < 0)
1211  DBG ("user input handler error");
1212  if (memif_err < 0)
1213  DBG ("memif control fd handler error");
1214  return -1;
1215  }
1216 
1217  return 0;
1218 }
1219 
1220 int
1222 {
1223  epfd = epoll_create (1);
1224  add_epoll_fd (0, EPOLLIN);
1225 
1226  flow = NULL;
1227 
1228 #ifdef LOG_FILE
1229  remove (LOG_FILE);
1230  enable_log = 0;
1231 
1232  out_fd = open (LOG_FILE, O_WRONLY | O_CREAT, S_IRWXO);
1233  if (out_fd < 0)
1234  INFO ("Error opening log file: %s", strerror (errno));
1235 #endif /* LOG_FILE */
1236 
1237  /* initialize memory interface */
1238  int err, i;
1239  /* if valid callback is passed as argument, fd event polling will be done by user
1240  all file descriptors and events will be passed to user in this callback */
1241  /* if callback is set to NULL libmemif will handle fd event polling */
1242  err = memif_init (control_fd_update, APP_NAME, NULL, NULL, NULL);
1243  if (err != MEMIF_ERR_SUCCESS)
1244  {
1245  INFO ("memif_init: %s", memif_strerror (err));
1246  icmpr_free ();
1247  exit (-1);
1248  }
1249 
1250  for (i = 0; i < MAX_CONNS; i++)
1251  {
1252  memif_connection[i].conn = NULL;
1253  ctx[i] = i;
1254  }
1255 
1256  print_help ();
1257 
1258  /* main loop */
1259  while (1)
1260  {
1261  if (poll_event (0) < 0)
1262  {
1263  DBG ("poll_event error!");
1264  }
1265  if (flow)
1266  {
1267  icmpr_send_proc ();
1268  }
1269  }
1270 }
memif_queue_details_t::head
uint16_t head
Definition: libmemif.h:361
icmpr_flow_t
Definition: main.c:109
tmp
u32 * tmp
Definition: interface_output.c:1078
MEMIF_FD_EVENT_MOD
#define MEMIF_FD_EVENT_MOD
update events
Definition: libmemif.h:98
out_fd
int out_fd
Definition: main.c:92
icmpr_set_ip
int icmpr_set_ip(long index, char *ip)
Definition: main.c:803
epfd
int epfd
Definition: main.c:94
MEMIF_RX_MODE_INTERRUPT
@ MEMIF_RX_MODE_INTERRUPT
Definition: libmemif.h:314
icmpr_print_counters
void icmpr_print_counters()
Definition: main.c:272
resolve_packet2
int resolve_packet2(void *pck, uint32_t *size, uint8_t ip_addr[4])
Definition: icmp_proto.c:381
memif_queue_details_t::flags
uint16_t flags
Definition: libmemif.h:360
MEMIF_FD_EVENT_WRITE
#define MEMIF_FD_EVENT_WRITE
Definition: libmemif.h:92
on_connect
int on_connect(memif_conn_handle_t conn, void *private_ctx)
Definition: main.c:177
memif_conn_args_t::mode
memif_interface_mode_t mode
Definition: libmemif.h:308
ICMPR_FLOW_MODE_IP
@ ICMPR_FLOW_MODE_IP
Definition: icmp_proto.h:24
control_fd_update
int control_fd_update(int fd, uint8_t events, void *ctx)
Definition: main.c:378
icmpr_free
int icmpr_free()
Definition: main.c:258
HEADROOM
#define HEADROOM
Definition: main.c:55
IF_NAME
#define IF_NAME
Definition: main.c:53
MEMIF_ERR_SUCCESS
@ MEMIF_ERR_SUCCESS
Definition: libmemif.h:38
icmpr_flow_t::sequence
uint16_t sequence
Definition: main.c:114
flow
icmpr_flow_t * flow
Definition: main.c:123
LOG
#define LOG(...)
Definition: main.c:73
icmpr_memif_create
int icmpr_memif_create(int is_master)
Definition: main.c:340
memif_details_t::remote_if_name
uint8_t * remote_if_name
Definition: libmemif.h:405
string.h
MEMIF_ERR_NOBUF_RING
@ MEMIF_ERR_NOBUF_RING
Definition: libmemif.h:59
user_input_handler
int user_input_handler()
Definition: main.c:894
TIME_UTC
#define TIME_UTC
Definition: main.c:51
memif_queue_details_t::tail
uint16_t tail
Definition: libmemif.h:362
memif_conn_args_t::buffer_size
uint16_t buffer_size
Definition: libmemif.h:302
memif_queue_details_t::ring_size
uint32_t ring_size
Definition: libmemif.h:357
memif_create
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.
Definition: main.c:1065
libmemif.h
memif_conn_args_t
Memif connection arguments.
Definition: libmemif.h:295
memif_buffer_enq_tx
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.
Definition: main.c:2204
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
flow
Definition: flow_types.api:196
add_epoll_fd
int add_epoll_fd(int fd, uint32_t events)
Definition: main.c:302
memif_get_details
int memif_get_details(memif_conn_handle_t conn, memif_details_t *md, char *buf, ssize_t buflen)
Memif get details.
Definition: main.c:2637
memif_details_t::tx_queues
memif_queue_details_t * tx_queues
Definition: libmemif.h:418
icmpr_flow_mode_t
icmpr_flow_mode_t
Definition: icmp_proto.h:21
memif_details_t::rx_queues_num
uint8_t rx_queues_num
Definition: libmemif.h:415
memif_conn_args_t::interface_id
uint32_t interface_id
Definition: libmemif.h:306
del_epoll_fd
int del_epoll_fd(int fd)
Definition: main.c:344
error
Definition: cJSON.c:88
on_disconnect
int on_disconnect(memif_conn_handle_t conn, void *private_ctx)
Definition: main.c:186
on_interrupt0
int on_interrupt0(memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
Definition: main.c:447
memif_details_t::inst_name
uint8_t * inst_name
Definition: libmemif.h:404
generate_packet2
int generate_packet2(void *pck, uint32_t *size, uint8_t saddr[4], uint8_t daddr[4], uint8_t hw_daddr[6], uint32_t seq, icmpr_flow_mode_t mode)
Definition: icmp_proto.c:343
memif_queue_details_t::buffer_size
uint16_t buffer_size
Definition: libmemif.h:363
on_interrupt
int on_interrupt(memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
Definition: main.c:287
memif_init
int memif_init(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 initialization.
Definition: main.c:502
memif_details_t::id
uint32_t id
Definition: libmemif.h:408
memif_details_t
Memif details.
Definition: libmemif.h:401
memif_get_version
uint16_t memif_get_version()
Memif get version.
Definition: main.c:171
poll_event
int poll_event(int timeout)
Definition: main.c:975
memif_connection_t
struct memif_connection memif_connection_t
Definition: memif_private.h:137
end
f64 end
end of the time range
Definition: mactime.api:44
memif_conn_args_t::num_m2s_rings
uint8_t num_m2s_rings
Definition: libmemif.h:301
icmpr_flow_t::mode
icmpr_flow_mode_t mode
Definition: main.c:112
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
icmpr_flow_t::index
uint16_t index
Definition: main.c:111
resolve_packet3
int resolve_packet3(void **pck_, uint32_t *size, uint8_t ip_addr[4])
Definition: icmp_proto.c:458
enable_log
uint8_t enable_log
Definition: main.c:93
memif_details_t::remote_inst_name
uint8_t * remote_inst_name
Definition: libmemif.h:406
memif_buffer_alloc
int memif_buffer_alloc(memif_conn_handle_t conn, uint16_t qid, memif_buffer_t *bufs, uint16_t count, uint16_t *count_out, uint16_t size)
Memif buffer alloc.
Definition: main.c:2265
LIBMEMIF_VERSION
#define LIBMEMIF_VERSION
Libmemif version.
Definition: libmemif.h:26
memif_details_t::tx_queues_num
uint8_t tx_queues_num
Definition: libmemif.h:416
icmpr_flow_t::start
struct timespec * start
Definition: main.c:118
time.h
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
memif_details_t::secret
uint8_t * secret
Definition: libmemif.h:409
events
static perfmon_event_t events[]
Definition: core.c:21
memif_set_rx_mode
int memif_set_rx_mode(memif_conn_handle_t c, memif_rx_mode_t rx_mode, uint16_t qid)
Memif set rx mode.
Definition: main.c:833
icmpr_set_rx_mode
int icmpr_set_rx_mode(long index, long qid, char *mode)
Definition: main.c:861
memif_cleanup
int memif_cleanup()
Memif cleanup.
Definition: main.c:2821
INFO
#define INFO(...)
Definition: main.c:76
icmpr_reset_counters
void icmpr_reset_counters()
Definition: main.c:289
MEMIF_FD_EVENT_ERROR
#define MEMIF_FD_EVENT_ERROR
inform libmemif that error occurred on fd
Definition: libmemif.h:94
icmpr_flow_t::tx
uint64_t tx
Definition: main.c:115
memif_details_t::if_name
uint8_t * if_name
Definition: libmemif.h:403
memif_connection
Definition: main.c:57
MEMIF_ERR_NOBUF
@ MEMIF_ERR_NOBUF
Definition: libmemif.h:60
MEMIF_FD_EVENT_DEL
#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)
Definition: libmemif.h:96
MAX_MEMIF_BUFS
#define MAX_MEMIF_BUFS
Definition: main.c:83
memif_connection_t::bufs
memif_buffer_t * bufs
Definition: main.c:96
ICMPR_FLOW_MODE_ETH
@ ICMPR_FLOW_MODE_ETH
Definition: icmp_proto.h:23
memif_conn_handle_t
void * memif_conn_handle_t
Memif connection handle pointer of type void, pointing to internal structure.
Definition: libmemif.h:110
icmpr_send
int icmpr_send(long index, long packet_num, char *hw, char *ip)
Definition: main.c:817
memif_details_t::socket_filename
uint8_t * socket_filename
Definition: libmemif.h:412
index
u32 index
Definition: flow_types.api:221
main
int main(int argc, char *argv[])
Definition: main.c:106
memif_conn_args_t::num_s2m_rings
uint8_t num_s2m_rings
Definition: libmemif.h:300
memif_tx_burst
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.
Definition: main.c:2444
memif_buffer_t
Memif buffer.
Definition: libmemif.h:325
APP_NAME
#define APP_NAME
Definition: main.c:52
memif_control_fd_handler
int memif_control_fd_handler(int fd, uint8_t events)
Memif control file descriptor handler.
Definition: main.c:1277
buf
u64 buf
Definition: application.c:493
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
MEMIF_RX_MODE_POLLING
@ MEMIF_RX_MODE_POLLING
Definition: libmemif.h:315
memif_conn_args_t::log2_ring_size
uint8_t log2_ring_size
Definition: libmemif.h:303
icmpr_send_proc
void * icmpr_send_proc(void *data)
Definition: main.c:720
memif_details_t::mode
uint8_t mode
Definition: libmemif.h:411
memif_details_t::link_up_down
uint8_t link_up_down
Definition: libmemif.h:421
print_memif_details
static void print_memif_details()
Definition: main.c:127
memif_conn_args_t::is_master
uint8_t is_master
Definition: libmemif.h:304
memif_conn_args_t::interface_name
uint8_t interface_name[32]
Definition: libmemif.h:307
memif_delete
int memif_delete(memif_conn_handle_t *conn)
Memif delete.
Definition: main.c:1784
memif_connection_t
Definition: main.c:72
icmp_proto.h
MAX_CONNS
#define MAX_CONNS
Definition: main.c:84
DBG
#define DBG(...)
Definition: main.c:72
a
a
Definition: bitmap.h:544
memif_details_t::role
uint8_t role
Definition: libmemif.h:410
ip
vl_api_address_t ip
Definition: l2.api:558
free
void free(void *p)
Definition: mem.c:42
icmpr_memif_delete
int icmpr_memif_delete()
Definition: main.c:193
memif_strerror
char * memif_strerror(int err_code)
Memif strerror.
Definition: main.c:157
malloc
void * malloc(size_t size)
Definition: mem.c:33
print_help
void print_help()
Definition: main.c:204
memif_details_t::rx_queues
memif_queue_details_t * rx_queues
Definition: libmemif.h:417
icmpr_flow_t::packet_count
uint64_t packet_count
Definition: main.c:113
MEMIF_ERR_NOCONN
@ MEMIF_ERR_NOCONN
Definition: libmemif.h:52
memif_refill_queue
int memif_refill_queue(memif_conn_handle_t conn, uint16_t qid, uint16_t count, uint16_t headroom)
Memif refill queue.
Definition: main.c:2389
MEMIF_FD_EVENT_READ
#define MEMIF_FD_EVENT_READ
user needs to set events that occurred on fd and pass them to memif_control_fd_handler
Definition: libmemif.h:91
memif_rx_burst
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.
Definition: main.c:2545
on_interrupt1
int on_interrupt1(memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
Definition: main.c:571
memif_queue_details_t::qid
uint8_t qid
Definition: libmemif.h:356
mod_epoll_fd
int mod_epoll_fd(int fd, uint32_t events)
Definition: main.c:323