[MERGED] libosmo-netif[master]: tests: osmo-pcap: Fix per packet timer

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Aug 9 09:55:08 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: tests: osmo-pcap: Fix per packet timer
......................................................................


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
---
M tests/osmo-pcap-test/osmo_pcap.h
M tests/osmo-pcap-test/pcap.c
2 files changed, 13 insertions(+), 7 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



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 @@
 	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 @@
 } 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 @@
 	/* 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 @@
 	memcpy(msgb->data, pkt, pktlen);
 	msgb_put(msgb, pktlen);
 
-	ret = cb(msgb);
+	*msgptr = msgb;
 
-	osmo_pcap_test_stats.processed++;
-
-	return ret;
+	return 0;
 }
 
 pcap_t *osmo_pcap_test_open(const char *pcapfile)
@@ -109,6 +108,12 @@
 	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 @@
 		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 */

-- 
To view, visit https://gerrit.osmocom.org/3063
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I715865c1edd1fc2ec9b024671d91eb72559cbdea
Gerrit-PatchSet: 2
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list