[ovs-dev,V7,08/18] netdev-offload-dpdk: Implement flow get method
diff mbox series

Message ID 20200109074655.1104-9-elibr@mellanox.com
State Accepted
Delegated to: Ilya Maximets
Headers show
Series
  • netdev datapath actions offload
Related show

Commit Message

Eli Britstein Jan. 9, 2020, 7:46 a.m. UTC
Implement the flow get method for DPDK, to get the statistics of the
provided ufid, towards reading statistics of fully offloaded flows.

Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
---
 lib/netdev-offload-dpdk.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

Patch
diff mbox series

diff --git a/lib/netdev-offload-dpdk.c b/lib/netdev-offload-dpdk.c
index 4fa4df0d9..55e266072 100644
--- a/lib/netdev-offload-dpdk.c
+++ b/lib/netdev-offload-dpdk.c
@@ -57,6 +57,7 @@  struct ufid_to_rte_flow_data {
     ovs_u128 ufid;
     struct rte_flow *rte_flow;
     bool actions_offloaded;
+    struct dpif_flow_stats stats;
 };
 
 /* Find rte_flow with @ufid. */
@@ -964,9 +965,55 @@  netdev_offload_dpdk_init_flow_api(struct netdev *netdev)
     return netdev_dpdk_flow_api_supported(netdev) ? 0 : EOPNOTSUPP;
 }
 
+static int
+netdev_offload_dpdk_flow_get(struct netdev *netdev,
+                             struct match *match OVS_UNUSED,
+                             struct nlattr **actions OVS_UNUSED,
+                             const ovs_u128 *ufid,
+                             struct dpif_flow_stats *stats,
+                             struct dpif_flow_attrs *attrs,
+                             struct ofpbuf *buf OVS_UNUSED)
+{
+    struct rte_flow_query_count query = { .reset = 1 };
+    struct ufid_to_rte_flow_data *rte_flow_data;
+    struct rte_flow_error error;
+    int ret = 0;
+
+    rte_flow_data = ufid_to_rte_flow_data_find(ufid);
+    if (!rte_flow_data || !rte_flow_data->rte_flow) {
+        ret = -1;
+        goto out;
+    }
+
+    attrs->offloaded = true;
+    if (!rte_flow_data->actions_offloaded) {
+        attrs->dp_layer = "ovs";
+        memset(stats, 0, sizeof *stats);
+        goto out;
+    }
+    attrs->dp_layer = "dpdk";
+    ret = netdev_dpdk_rte_flow_query_count(netdev, rte_flow_data->rte_flow,
+                                           &query, &error);
+    if (ret) {
+        VLOG_DBG_RL(&rl, "%s: Failed to query ufid "UUID_FMT" flow: %p\n",
+                    netdev_get_name(netdev), UUID_ARGS((struct uuid *)ufid),
+                    rte_flow_data->rte_flow);
+        goto out;
+    }
+    rte_flow_data->stats.n_packets += (query.hits_set) ? query.hits : 0;
+    rte_flow_data->stats.n_bytes += (query.bytes_set) ? query.bytes : 0;
+    if (query.hits_set && query.hits) {
+        rte_flow_data->stats.used = time_msec();
+    }
+    memcpy(stats, &rte_flow_data->stats, sizeof *stats);
+out:
+    return ret;
+}
+
 const struct netdev_flow_api netdev_offload_dpdk = {
     .type = "dpdk_flow_api",
     .flow_put = netdev_offload_dpdk_flow_put,
     .flow_del = netdev_offload_dpdk_flow_del,
     .init_flow_api = netdev_offload_dpdk_init_flow_api,
+    .flow_get = netdev_offload_dpdk_flow_get,
 };