summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Ribas <jonathan.ribas@fraudbuster.mobi>2019-01-26 20:53:56 +0100
committerJonathan Ribas <jonathan.ribas@fraudbuster.mobi>2019-01-26 21:11:25 +0100
commitc954761dc5dbe7a311d379c01626d84984b51bfe (patch)
tree5f855b812e348f5ea05877bce259bff97e31a4b3
parentf14dc4286b20d7cd4e72bc6ccf8430770a04f6a3 (diff)
downloaddpdk-burst-replay-c954761dc5dbe7a311d379c01626d84984b51bfe.zip
dpdk-burst-replay-c954761dc5dbe7a311d379c01626d84984b51bfe.tar.gz
dpdk-burst-replay-c954761dc5dbe7a311d379c01626d84984b51bfe.tar.xz
When loading the pcap, store the retrieved packets timestamp.
-rw-r--r--src/dpdk.c4
-rw-r--r--src/main.h7
-rw-r--r--src/pcap.c9
3 files changed, 20 insertions, 0 deletions
diff --git a/src/dpdk.c b/src/dpdk.c
index 123eb7d..ad87446 100644
--- a/src/dpdk.c
+++ b/src/dpdk.c
@@ -487,6 +487,10 @@ void dpdk_cleanup(struct dpdk_ctx* dpdk, struct cpus_bindings* cpus)
free(dpdk->pcap_caches);
}
+ /* free the timestamps cache */
+ if (dpdk->pkts_ts)
+ free(dpdk->pkts_ts);
+
/* close ethernet devices */
for (i = 0; i < cpus->nb_needed_cpus; i++)
rte_eth_dev_close(i);
diff --git a/src/main.h b/src/main.h
index 660596f..7849693 100644
--- a/src/main.h
+++ b/src/main.h
@@ -55,6 +55,12 @@ struct pcap_cache {
struct rte_mbuf** mbufs;
};
+/* timestamp of packets */
+struct pcap_pkt_ts {
+ uint32_t sec; /* timestamp seconds */
+ uint32_t usec; /* timestamp microseconds */
+};
+
/* struct to store dpdk context */
struct dpdk_ctx {
unsigned long nb_mbuf; /* number of needed mbuf (see main.c) */
@@ -65,6 +71,7 @@ struct dpdk_ctx {
/* pcap file caches */
long int pcap_sz; /* size of the capture */
struct pcap_cache* pcap_caches; /* tab of caches, one per NIC port */
+ struct pcap_pkt_ts* pkts_ts; /* timestamps of packets */
};
/* struct to store threads context */
diff --git a/src/pcap.c b/src/pcap.c
index 5b04301..7a64876 100644
--- a/src/pcap.c
+++ b/src/pcap.c
@@ -224,6 +224,13 @@ int load_pcap(const struct cmd_opts* opts, struct pcap_ctx* pcap,
bzero(dpdk->pcap_caches[i].mbufs,
sizeof(*(dpdk->pcap_caches[i].mbufs)) * pcap->nb_pkts);
}
+ /* alloc needed tab of timestamps */
+ dpdk->pkts_ts = malloc(sizeof(*(dpdk->pkts_ts)) * pcap->nb_pkts);
+ if (dpdk->pkts_ts == NULL) {
+ fprintf(stderr, "%s: malloc of pkt_ts failed.\n", __FUNCTION__);
+ return (ENOMEM);
+ }
+ bzero(dpdk->pkts_ts, sizeof(*(dpdk->pkts_ts)) * pcap->nb_pkts);
/* seek again to the beginning */
if (lseek(pcap->fd, 0, SEEK_SET) == (off_t)(-1)) {
@@ -275,6 +282,8 @@ int load_pcap(const struct cmd_opts* opts, struct pcap_ctx* pcap,
goto load_pcapError;
}
}
+ dpdk->pkts_ts[cpt].sec = pcap_rechdr.ts_sec;
+ dpdk->pkts_ts[cpt].usec = pcap_rechdr.ts_usec;
/* calcul & print progression every 1024 pkts */
if ((cpt % 1024) == 0) {