Support packets in flight
[samplevnf.git] / VNFs / DPPD-PROX / handle_dump.c
index c35a6e9..8fbc514 100644 (file)
 #include "task_init.h"
 #include "task_base.h"
 #include "stats.h"
+#include "prox_compat.h"
 
 struct task_dump {
        struct task_base base;
        uint32_t n_mbufs;
         struct rte_mbuf **mbufs;
        uint32_t n_pkts;
-       char pcap_file[128];
+       char pcap_file[256];
 };
 
 static uint16_t buffer_packets(struct task_dump *task, struct rte_mbuf **mbufs, uint16_t n_pkts)
@@ -41,7 +42,12 @@ static uint16_t buffer_packets(struct task_dump *task, struct rte_mbuf **mbufs,
                return 0;
 
        for (j = 0; j < n_pkts && task->n_mbufs < task->n_pkts; ++j) {
+#if RTE_VERSION >= RTE_VERSION_NUM(20,11,0,0)
+               uint64_t rdtsc = rte_rdtsc();
+               memcpy(&mbufs[j]->dynfield1[0], &rdtsc, sizeof(rdtsc));
+#else
                mbufs[j]->udata64 = rte_rdtsc();
+#endif
                task->mbufs[task->n_mbufs++] = mbufs[j];
        }
 
@@ -64,12 +70,14 @@ static void init_task_dump(struct task_base *tbase, __attribute__((unused)) stru
        struct task_dump *task = (struct task_dump *)tbase;
        const int socket_id = rte_lcore_to_socket_id(targ->lconf->id);
 
+       if (targ->n_pkts == 0)
+               targ->n_pkts = 64 * 1024;
        task->mbufs = prox_zmalloc(sizeof(*task->mbufs) * targ->n_pkts, socket_id);
        task->n_pkts = targ->n_pkts;
        if (!strcmp(targ->pcap_file, "")) {
                strcpy(targ->pcap_file, "out.pcap");
        }
-       strncpy(task->pcap_file, targ->pcap_file, sizeof(task->pcap_file));
+       prox_strncpy(task->pcap_file, targ->pcap_file, sizeof(task->pcap_file));
 }
 
 static void stop(struct task_base *tbase)
@@ -90,10 +98,20 @@ static void stop(struct task_base *tbase)
        pcap_dump_handle = pcap_dump_open(handle, task->pcap_file);
 
        if (task->n_mbufs) {
+#if RTE_VERSION >= RTE_VERSION_NUM(20,11,0,0)
+               memcpy(&beg, &task->mbufs[0]->dynfield1[0], sizeof(beg));
+#else
                beg = task->mbufs[0]->udata64;
+#endif
        }
        for (uint32_t j = 0; j < task->n_mbufs; ++j) {
+#if RTE_VERSION >= RTE_VERSION_NUM(20,11,0,0)
+               uint64_t mbufs_beg;
+               memcpy(&mbufs_beg, &task->mbufs[j]->dynfield1[0], sizeof(mbufs_beg));
+               tsc = mbufs_beg - beg;
+#else
                tsc = task->mbufs[j]->udata64 - beg;
+#endif
                header.len = rte_pktmbuf_pkt_len(task->mbufs[j]);
                header.caplen = header.len;
                tsc_to_tv(&header.ts, tsc);