diff mbox

[API-NEXT,02/11] linux-generic: packet: implement timestamp support

Message ID 1460704874-21163-3-git-send-email-matias.elo@nokia.com
State Superseded
Headers show

Commit Message

Elo, Matias (Nokia - FI/Espoo) April 15, 2016, 7:21 a.m. UTC
Implements support for packet timestamps and adds related
validation tests.

Signed-off-by: Matias Elo <matias.elo@nokia.com>
---
 platform/linux-generic/include/odp_packet_internal.h |  2 ++
 platform/linux-generic/odp_packet.c                  | 15 +++++++++++++++
 platform/linux-generic/odp_packet_flags.c            | 14 ++++++++++++++
 test/validation/packet/packet.c                      |  8 ++++++++
 4 files changed, 39 insertions(+)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 0084d14..0459286 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -42,6 +42,7 @@  typedef union {
 		uint32_t parsed_all:1;/**< Parsing complete */
 
 		uint32_t flow_hash:1; /**< Flow hash present */
+		uint32_t timestamp:1; /**< Timestamp present */
 
 		uint32_t l2:1;        /**< known L2 protocol present */
 		uint32_t l3:1;        /**< known L3 protocol present */
@@ -152,6 +153,7 @@  typedef struct {
 	odp_pktio_t input;
 
 	uint32_t flow_hash;      /**< Flow hash value */
+	odp_time_t timestamp;    /**< Timestamp value */
 
 	odp_crypto_generic_op_result_t op_result;  /**< Result for crypto */
 } odp_packet_hdr_t;
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 829fbb5..6a6055e 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -451,6 +451,21 @@  void odp_packet_flow_hash_set(odp_packet_t pkt, uint32_t flow_hash)
 	pkt_hdr->input_flags.flow_hash = 1;
 }
 
+odp_time_t odp_packet_ts(odp_packet_t pkt)
+{
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	return pkt_hdr->timestamp;
+}
+
+void odp_packet_ts_set(odp_packet_t pkt, odp_time_t timestamp)
+{
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	pkt_hdr->timestamp = timestamp;
+	pkt_hdr->input_flags.timestamp = 1;
+}
+
 int odp_packet_is_segmented(odp_packet_t pkt)
 {
 	return odp_packet_hdr(pkt)->buf_hdr.segcount > 1;
diff --git a/platform/linux-generic/odp_packet_flags.c b/platform/linux-generic/odp_packet_flags.c
index 5d93f57..3acdc53 100644
--- a/platform/linux-generic/odp_packet_flags.c
+++ b/platform/linux-generic/odp_packet_flags.c
@@ -179,6 +179,13 @@  int odp_packet_has_flow_hash(odp_packet_t pkt)
 	return pkt_hdr->input_flags.flow_hash;
 }
 
+int odp_packet_has_ts(odp_packet_t pkt)
+{
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	return pkt_hdr->input_flags.timestamp;
+}
+
 odp_packet_color_t odp_packet_color(odp_packet_t pkt)
 {
 	retflag(pkt, input_flags.color);
@@ -337,3 +344,10 @@  void odp_packet_has_flow_hash_clr(odp_packet_t pkt)
 
 	pkt_hdr->input_flags.flow_hash = 0;
 }
+
+void odp_packet_has_ts_clr(odp_packet_t pkt)
+{
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	pkt_hdr->input_flags.timestamp = 0;
+}
diff --git a/test/validation/packet/packet.c b/test/validation/packet/packet.c
index a764ed9..ff7a268 100644
--- a/test/validation/packet/packet.c
+++ b/test/validation/packet/packet.c
@@ -245,6 +245,7 @@  void packet_test_event_conversion(void)
 void packet_test_basic_metadata(void)
 {
 	odp_packet_t pkt = test_packet;
+	odp_time_t ts;
 
 	CU_ASSERT_PTR_NOT_NULL(odp_packet_head(pkt));
 	CU_ASSERT_PTR_NOT_NULL(odp_packet_data(pkt));
@@ -258,6 +259,13 @@  void packet_test_basic_metadata(void)
 	CU_ASSERT(odp_packet_flow_hash(pkt) == UINT32_MAX);
 	odp_packet_has_flow_hash_clr(pkt);
 	CU_ASSERT(!odp_packet_has_flow_hash(pkt));
+
+	ts = odp_time_global();
+	odp_packet_ts_set(pkt, ts);
+	CU_ASSERT_FATAL(odp_packet_has_ts(pkt));
+	CU_ASSERT(!odp_time_cmp(ts, odp_packet_ts(pkt)));
+	odp_packet_has_ts_clr(pkt);
+	CU_ASSERT(!odp_packet_has_ts(pkt));
 }
 
 void packet_test_length(void)