Add a function to read the current input policy of netdev instances.
Implement the call for linux and dpdk interfaces.

Signed-off-by: Gaetan Rivet <[email protected]>
---
 lib/netdev-dpdk.c     | 20 ++++++++++++++++++++
 lib/netdev-linux.c    | 20 ++++++++++++++++++++
 lib/netdev-provider.h |  5 +++++
 lib/netdev.c          | 18 ++++++++++++++++++
 lib/netdev.h          |  4 ++++
 5 files changed, 67 insertions(+)

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 687e1196b5..9ec5abbf33 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -4253,6 +4253,25 @@ netdev_dpdk_set_policing(struct netdev* netdev, uint32_t 
policer_rate,
     return 0;
 }
 
+static int
+netdev_dpdk_get_policing(struct netdev *netdev,
+                         uint32_t *kbits_rate, uint32_t *kbits_burst,
+                         uint32_t *kpkts_rate, uint32_t *kpkts_burst)
+{
+    struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+
+    ovs_mutex_lock(&dev->mutex);
+
+    *kbits_rate = dev->policer_rate;
+    *kbits_burst = dev->policer_burst;
+    *kpkts_rate = 0;
+    *kpkts_burst = 0;
+
+    ovs_mutex_unlock(&dev->mutex);
+
+    return 0;
+}
+
 static int
 netdev_dpdk_get_ifindex(const struct netdev *netdev)
 {
@@ -6857,6 +6876,7 @@ parse_vhost_config(const struct smap *ovs_other_config)
     .get_carrier_resets = netdev_dpdk_get_carrier_resets,   \
     .set_miimon_interval = netdev_dpdk_set_miimon,          \
     .set_policing = netdev_dpdk_set_policing,               \
+    .get_policing = netdev_dpdk_get_policing,               \
     .get_qos_types = netdev_dpdk_get_qos_types,             \
     .get_qos = netdev_dpdk_get_qos,                         \
     .set_qos = netdev_dpdk_set_qos,                         \
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 8bf1a29a0f..849f6ba821 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -3129,6 +3129,25 @@ out:
     return error;
 }
 
+static int
+netdev_linux_get_policing(struct netdev *netdev_,
+                          uint32_t *kbits_rate, uint32_t *kbits_burst,
+                          uint32_t *kpkts_rate, uint32_t *kpkts_burst)
+{
+    struct netdev_linux *netdev = netdev_linux_cast(netdev_);
+
+    ovs_mutex_lock(&netdev->mutex);
+
+    *kbits_rate = netdev->kbits_rate;
+    *kbits_burst = netdev->kbits_burst;
+    *kpkts_rate = netdev->kpkts_rate;
+    *kpkts_burst = netdev->kpkts_burst;
+
+    ovs_mutex_unlock(&netdev->mutex);
+
+    return 0;
+}
+
 static int
 netdev_linux_get_qos_types(const struct netdev *netdev OVS_UNUSED,
                            struct sset *types)
@@ -3905,6 +3924,7 @@ exit:
     .set_miimon_interval = netdev_linux_set_miimon_interval,    \
     .set_advertisements = netdev_linux_set_advertisements,      \
     .set_policing = netdev_linux_set_policing,                  \
+    .get_policing = netdev_linux_get_policing,                  \
     .get_qos_types = netdev_linux_get_qos_types,                \
     .get_qos_capabilities = netdev_linux_get_qos_capabilities,  \
     .get_qos = netdev_linux_get_qos,                            \
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 33a68c49c2..b12724cbd0 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -546,6 +546,11 @@ struct netdev_class {
                         unsigned int kbits_burst, unsigned int kpkts_rate,
                         unsigned int kpkts_burst);
 
+    /* Read the input rate limiting (policing) policy, if possible. */
+    int (*get_policing)(struct netdev *netdev,
+                        uint32_t *kbits_rate, uint32_t *kbits_burst,
+                        uint32_t *kpkts_rate, uint32_t *kpkts_burst);
+
     /* Adds to 'types' all of the forms of QoS supported by 'netdev', or leaves
      * it empty if 'netdev' does not support QoS.  Any names added to 'types'
      * should be documented as valid for the "type" column in the "QoS" table
diff --git a/lib/netdev.c b/lib/netdev.c
index 6a05e9a7e5..edd79d52f5 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1784,6 +1784,24 @@ netdev_set_policing(struct netdev *netdev, uint32_t 
kbits_rate,
             : EOPNOTSUPP);
 }
 
+
+/* Read the input rate limiting (policing) policy, if possible. */
+int
+netdev_get_policing(struct netdev *netdev,
+                    uint32_t *kbits_rate, uint32_t *kbits_burst,
+                    uint32_t *kpkts_rate, uint32_t *kpkts_burst)
+{
+    *kbits_rate = 0;
+    *kbits_burst = 0;
+    *kpkts_rate = 0;
+    *kpkts_burst = 0;
+
+    return (netdev->netdev_class->get_policing
+            ? netdev->netdev_class->get_policing(netdev,
+                    kbits_rate, kbits_burst, kpkts_rate, kpkts_burst)
+            : EOPNOTSUPP);
+}
+
 /* Adds to 'types' all of the forms of QoS supported by 'netdev', or leaves it
  * empty if 'netdev' does not support QoS.  Any names added to 'types' should
  * be documented as valid for the "type" column in the "QoS" table in
diff --git a/lib/netdev.h b/lib/netdev.h
index 63e03d72db..92320ae812 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -326,6 +326,10 @@ int netdev_set_policing(struct netdev *, uint32_t 
kbits_rate,
                         uint32_t kbits_burst, uint32_t kpkts_rate,
                         uint32_t kpkts_burst);
 
+int netdev_get_policing(struct netdev *,
+                        uint32_t *kbits_rate, uint32_t *kbits_burst,
+                        uint32_t *kpkts_rate, uint32_t *kpkts_burst);
+
 int netdev_get_qos_types(const struct netdev *, struct sset *types);
 int netdev_get_qos_capabilities(const struct netdev *,
                                 const char *type,
-- 
2.34.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to