+void
+icmpr_print_counters ()
+{
+ int i;
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+ if (c->conn == NULL)
+ continue;
+ printf ("===============================\n");
+ printf ("interface index: %d\n", c->index);
+ printf ("\trx: %lu\n", c->rx_counter);
+ printf ("\ttx: %lu\n", c->tx_counter);
+ printf ("\ttx_err: %lu\n", c->tx_err_counter);
+ printf ("\tts: %lus %luns\n", c->t_sec, c->t_nsec);
+ }
+}
+
+void
+icmpr_reset_counters ()
+{
+ int i;
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+ if (c->conn == NULL)
+ continue;
+ c->t_sec = c->t_nsec = c->tx_err_counter = c->tx_counter =
+ c->rx_counter = 0;
+ }
+}
+
+void *
+icmpr_send_proc (void *data)
+{
+ icmpr_thread_data_t *d = (icmpr_thread_data_t *) data;
+ int index = d->index;
+ uint64_t count = d->packet_num;
+ memif_connection_t *c = &memif_connection[index];
+ if (c->conn == NULL)
+ {
+ INFO ("No connection at index %d. Thread exiting...\n", index);
+ pthread_exit (NULL);
+ }
+ uint16_t tx, i;
+ int err = MEMIF_ERR_SUCCESS;
+ uint32_t seq = 0;
+ struct timespec start, end;
+ memset (&start, 0, sizeof (start));
+ memset (&end, 0, sizeof (end));
+
+ timespec_get (&start, TIME_UTC);
+ while (count)
+ {
+ i = 0;
+ err = memif_buffer_alloc (c->conn, 0, c->tx_bufs,
+ MAX_MEMIF_BUFS >
+ count ? count : MAX_MEMIF_BUFS, &tx, 0);
+ if ((err != MEMIF_ERR_SUCCESS) && (err != MEMIF_ERR_NOBUF_RING))
+ {
+ INFO ("memif_buffer_alloc: %s Thread exiting...\n",
+ memif_strerror (err));
+ pthread_exit (NULL);
+ }
+ c->tx_buf_num += tx;
+
+ while (tx)
+ {
+ while (tx > 2)
+ {
+ generate_packet ((void *) c->tx_bufs[i].data,
+ &c->tx_bufs[i].data_len, c->ip_addr,
+ d->ip_daddr, d->hw_daddr, seq++);
+ generate_packet ((void *) c->tx_bufs[i + 1].data,
+ &c->tx_bufs[i + 1].data_len, c->ip_addr,
+ d->ip_daddr, d->hw_daddr, seq++);
+ i += 2;
+ tx -= 2;
+ }
+ generate_packet ((void *) c->tx_bufs[i].data,
+ &c->tx_bufs[i].data_len, c->ip_addr,
+ d->ip_daddr, d->hw_daddr, seq++);
+ i++;
+ tx--;
+ }
+ err = memif_tx_burst (c->conn, 0, c->tx_bufs, c->tx_buf_num, &tx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_tx_burst: %s Thread exiting...\n",
+ memif_strerror (err));
+ pthread_exit (NULL);
+ }
+ c->tx_buf_num -= tx;
+ c->tx_counter += tx;
+ count -= tx;
+ }
+ timespec_get (&end, TIME_UTC);
+ INFO ("Pakcet sequence finished!");
+ INFO ("Seq len: %u", seq);
+ uint64_t t1 = end.tv_sec - start.tv_sec;
+ uint64_t t2;
+ if (end.tv_nsec > start.tv_nsec)
+ {
+ t2 = end.tv_nsec - start.tv_nsec;
+ }
+ else
+ {
+ t2 = start.tv_nsec - end.tv_nsec;
+ t1--;
+ }
+ c->t_sec = t1;
+ c->t_nsec = t2;
+ INFO ("Seq time: %lus %luns", t1, t2);
+ double tmp = t1;
+ tmp += t2 / 1e+9;
+ tmp = seq / tmp;
+ INFO ("Average pps: %f", tmp);
+ INFO ("Thread exiting...");
+ pthread_exit (NULL);
+}
+
+int
+icmpr_send (long index, long packet_num, char *hw, char *ip)
+{
+ memif_connection_t *c = &memif_connection[index];
+ char *end;
+ char *ui;
+ uint8_t tmp[6];
+ if (c->conn == NULL)
+ return -1;
+ c->seq = 0;
+ icmpr_thread_data_t *data = &icmpr_thread_data[index];
+ data->index = index;
+ data->packet_num = packet_num;
+ INFO ("PN: %lu", data->packet_num);
+ printf ("%s\n", ip);
+ printf ("%s\n", hw);
+
+ ui = strtok (ip, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[0] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[1] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[2] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[3] = strtol (ui, &end, 10);
+
+ data->ip_daddr[0] = tmp[0];
+ data->ip_daddr[1] = tmp[1];
+ data->ip_daddr[2] = tmp[2];
+ data->ip_daddr[3] = tmp[3];
+
+ ui = strtok (hw, ":");
+ if (ui == NULL)
+ goto error;
+ tmp[0] = strtol (ui, &end, 16);
+ ui = strtok (NULL, ":");
+ if (ui == NULL)
+ goto error;
+ tmp[1] = strtol (ui, &end, 16);
+ ui = strtok (NULL, ":");
+ if (ui == NULL)
+ goto error;
+ tmp[2] = strtol (ui, &end, 16);
+ ui = strtok (NULL, ":");
+ if (ui == NULL)
+ goto error;
+ tmp[3] = strtol (ui, &end, 16);
+ ui = strtok (NULL, ":");
+ if (ui == NULL)
+ goto error;
+ tmp[4] = strtol (ui, &end, 16);
+ ui = strtok (NULL, ":");
+ if (ui == NULL)
+ goto error;
+ tmp[5] = strtol (ui, &end, 16);
+
+ data->hw_daddr[0] = tmp[0];
+ data->hw_daddr[1] = tmp[1];
+ data->hw_daddr[2] = tmp[2];
+ data->hw_daddr[3] = tmp[3];
+ data->hw_daddr[4] = tmp[4];
+ data->hw_daddr[5] = tmp[5];
+
+ pthread_create (&thread[index], NULL, icmpr_send_proc, (void *) data);
+ return 0;
+
+error:
+ INFO ("Invalid input\n");
+ return 0;
+}
+