diff mbox series

[ovs-dev,ovs-dev,5/7] netdev-dpif: Implement netdev meter offload

Message ID 1577517076-105041-6-git-send-email-xiangxia.m.yue@gmail.com
State New
Headers show
Series Support meter action offload | expand

Commit Message

Tonghao Zhang Dec. 28, 2019, 7:11 a.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

Implement the meter offload api in the netdev.

Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
 lib/dpif-netdev.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 93 insertions(+), 3 deletions(-)

Comments

0-day Robot Dec. 28, 2019, 8:10 a.m. UTC | #1
Bleep bloop.  Greetings Tonghao Zhang, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line has non-spaces leading whitespace
WARNING: Line has trailing whitespace
#34 FILE: lib/dpif-netdev.c:5909:
    

WARNING: Line has non-spaces leading whitespace
WARNING: Line has trailing whitespace
#66 FILE: lib/dpif-netdev.c:5941:
    

WARNING: Line has non-spaces leading whitespace
WARNING: Line has trailing whitespace
#73 FILE: lib/dpif-netdev.c:5948:
    

WARNING: Line has non-spaces leading whitespace
WARNING: Line has trailing whitespace
#93 FILE: lib/dpif-netdev.c:5968:
    

WARNING: Line has non-spaces leading whitespace
WARNING: Line has trailing whitespace
#100 FILE: lib/dpif-netdev.c:5975:
    

Lines checked: 130, Warnings: 10, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
diff mbox series

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 051d090..e33215d 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -5893,6 +5893,96 @@  dpif_netdev_meter_del(struct dpif *dpif,
     return error;
 }
 
+static int
+dpif_netdev_meter_get_config(struct dpif *dpif,
+                             ofproto_meter_id meter_id,
+                             struct ofputil_meter_config *conf)
+{
+    struct dp_netdev *dp = get_dp_netdev(dpif);
+    uint32_t mid = meter_id.uint32;
+    struct dp_meter *meter;
+    int ret = 0, i;
+
+    if (mid >= MAX_METERS) {
+        return -1;
+    }
+    
+    meter_lock(dp, mid);
+    meter = dp->meters[mid];
+    if (!meter) {
+        ret = -1;
+        goto done;
+    }
+
+    conf->n_bands = meter->n_bands;
+    conf->bands = xzalloc(conf->n_bands * sizeof(struct dp_meter_band));
+    for (i = 0; i < meter->n_bands; ++i) {
+        conf->bands[i] = meter->bands[i].up;
+    }
+
+done:
+    meter_unlock(dp, mid);
+    return ret;
+}
+
+static int
+dpif_netdev_meter_set_offload(struct dpif *dpif,
+                              ofproto_meter_id meter_id,
+                              void *data)
+{
+    struct dp_netdev *dp = get_dp_netdev(dpif);
+    uint32_t mid = meter_id.uint32;
+    struct dp_meter *meter;
+    int ret = 0;
+
+    if (mid >= MAX_METERS) {
+        return -1;
+    }
+    
+    meter_lock(dp, mid);
+    meter = dp->meters[mid];
+    if (!meter) {
+        ret = -1;
+        goto done;
+    }
+    
+    meter->offload = (struct netdev_offload_meter *)data;
+done:
+    meter_unlock(dp, mid);
+    return ret;
+}
+
+static int
+dpif_netdev_meter_get_offload(struct dpif *dpif,
+                              ofproto_meter_id meter_id,
+                              void **data, uint16_t size)
+{
+    struct dp_netdev *dp = get_dp_netdev(dpif);
+    uint32_t mid = meter_id.uint32;
+    struct dp_meter *meter;
+    int ret = 0;
+
+    if (mid >= MAX_METERS) {
+        return -1;
+    }
+    
+    meter_lock(dp, mid);
+    meter = dp->meters[mid];
+    if (!meter) {
+        ret = -1;
+        goto done;
+    }
+    
+    *data = NULL;
+    if (meter->offload) {
+        *data = xmemdup(meter->offload, size);
+    }
+
+done:
+    meter_unlock(dp, mid);
+    return ret;
+}
+
 
 static void
 dpif_netdev_disable_upcall(struct dpif *dpif)
@@ -7681,9 +7771,9 @@  const struct dpif_class dpif_netdev_class = {
     dpif_netdev_meter_set,
     dpif_netdev_meter_get,
     dpif_netdev_meter_del,
-    NULL,
-    NULL,
-    NULL,
+    dpif_netdev_meter_get_config,
+    dpif_netdev_meter_set_offload,
+    dpif_netdev_meter_get_offload,
 };
 
 static void