aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2017-04-19 17:14:19 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2017-08-08 20:39:16 +0200
commit76c0acb149a03e6d7945e0ee4f4c6355381b7391 (patch)
tree0cedaa79bcd83198abbf1bf069bcc4698dc2dd5c /tests
parent243a3b0372fe738b01c2d32d6f6cb7b7c99a1180 (diff)
tests: osmo-pcap: Fix per packet timer
Before this commit, the gap time between 2 packets {n-1, n} was being applied to {n, n+1}. Change-Id: I715865c1edd1fc2ec9b024671d91eb72559cbdea
Diffstat (limited to 'tests')
-rw-r--r--tests/osmo-pcap-test/osmo_pcap.h1
-rw-r--r--tests/osmo-pcap-test/pcap.c19
2 files changed, 13 insertions, 7 deletions
diff --git a/tests/osmo-pcap-test/osmo_pcap.h b/tests/osmo-pcap-test/osmo_pcap.h
index cff638b..171360d 100644
--- a/tests/osmo-pcap-test/osmo_pcap.h
+++ b/tests/osmo-pcap-test/osmo_pcap.h
@@ -12,6 +12,7 @@ struct osmo_pcap {
pcap_t *h;
struct osmo_timer_list timer;
struct timeval last;
+ struct msgb *deliver_msg;
};
pcap_t *osmo_pcap_test_open(const char *pcapfile);
diff --git a/tests/osmo-pcap-test/pcap.c b/tests/osmo-pcap-test/pcap.c
index 8fa8e0f..61408f8 100644
--- a/tests/osmo-pcap-test/pcap.c
+++ b/tests/osmo-pcap-test/pcap.c
@@ -39,7 +39,8 @@ struct osmo_pcap_test_stats {
} osmo_pcap_test_stats;
static int
-osmo_pcap_process_packet(const uint8_t *pkt, uint32_t pktlen,
+osmo_pcap_process_packet(struct msgb **msgptr,
+ const uint8_t *pkt, uint32_t pktlen,
struct osmo_pcap_proto_l2l3 *l3h,
struct osmo_pcap_proto_l4 *l4h,
int (*cb)(struct msgb *msgb))
@@ -56,7 +57,7 @@ osmo_pcap_process_packet(const uint8_t *pkt, uint32_t pktlen,
/* This packet contains no data, skip it. */
if (l4h->l4pkt_no_data(pkt + l3hdr_len + ETH_HLEN)) {
osmo_pcap_test_stats.skip++;
- return 0;
+ return -1;
}
/* get application layer data. */
@@ -72,11 +73,9 @@ osmo_pcap_process_packet(const uint8_t *pkt, uint32_t pktlen,
memcpy(msgb->data, pkt, pktlen);
msgb_put(msgb, pktlen);
- ret = cb(msgb);
-
- osmo_pcap_test_stats.processed++;
+ *msgptr = msgb;
- return ret;
+ return 0;
}
pcap_t *osmo_pcap_test_open(const char *pcapfile)
@@ -109,6 +108,12 @@ osmo_pcap_test_run(struct osmo_pcap *p, uint8_t pnum, int (*cb)(struct msgb *msg
struct timeval res;
uint8_t l4protonum;
+ if (p->deliver_msg) {
+ if (cb(p->deliver_msg) == 0)
+ osmo_pcap_test_stats.processed++;
+ p->deliver_msg = 0;
+ }
+
retry:
pkt = pcap_next(p->h, &pcaph);
if (pkt == NULL)
@@ -140,7 +145,7 @@ retry:
memcpy(&p->last, &pcaph.ts, sizeof(struct timeval));
/* retry with next packet if this has been skipped. */
- if (osmo_pcap_process_packet(pkt, pcaph.caplen, l3h, l4h, cb) < 0)
+ if (osmo_pcap_process_packet(&p->deliver_msg, pkt, pcaph.caplen, l3h, l4h, cb) < 0)
goto retry;
/* calculate waiting time */