diff mbox series

[ovs-dev,v9,07/16] dpif-netdev: Add command to get dpif implementations.

Message ID 20210212171718.2189798-8-harry.van.haaren@intel.com
State New
Headers show
Series DPIF Framework + Optimizations | expand

Commit Message

Harry van Haaren Feb. 12, 2021, 5:17 p.m. UTC
This commit adds a new command to retrieve the list of available
DPIF implementations. This can be used by to check what implementations
of the DPIF are available in any given OVS binary.

Usage:
 $ ovs-appctl dpif-netdev/dpif-get

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 lib/dpif-netdev-private-dpif.c |  7 +++++++
 lib/dpif-netdev-private-dpif.h |  6 ++++++
 lib/dpif-netdev.c              | 24 ++++++++++++++++++++++++
 3 files changed, 37 insertions(+)
diff mbox series

Patch

diff --git a/lib/dpif-netdev-private-dpif.c b/lib/dpif-netdev-private-dpif.c
index 9e1f3b8f9..c5021fe9f 100644
--- a/lib/dpif-netdev-private-dpif.c
+++ b/lib/dpif-netdev-private-dpif.c
@@ -61,6 +61,13 @@  dp_netdev_impl_get_default(void)
     return func;
 }
 
+uint32_t
+dp_netdev_impl_get(const struct dpif_netdev_impl_info_t **out_impls)
+{
+    ovs_assert(out_impls);
+    *out_impls = dpif_impls;
+    return ARRAY_SIZE(dpif_impls);
+}
 
 /* This function checks all available DPIF implementations, and selects the
  * returns the function pointer to the one requested by "name".
diff --git a/lib/dpif-netdev-private-dpif.h b/lib/dpif-netdev-private-dpif.h
index a09f90acc..99fbda943 100644
--- a/lib/dpif-netdev-private-dpif.h
+++ b/lib/dpif-netdev-private-dpif.h
@@ -47,6 +47,12 @@  struct dpif_netdev_impl_info_t {
     const char *name;
 };
 
+/* This function returns all available implementations to the caller. The
+ * quantity of implementations is returned by the int return value.
+ */
+uint32_t
+dp_netdev_impl_get(const struct dpif_netdev_impl_info_t **out_impls);
+
 /* This function checks all available DPIF implementations, and selects the
  * returns the function pointer to the one requested by "name".
  */
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 564d94a97..dff844f99 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -992,6 +992,27 @@  dpif_netdev_subtable_lookup_set(struct unixctl_conn *conn, int argc,
     ds_destroy(&reply);
 }
 
+static void
+dpif_netdev_impl_get(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                     const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
+{
+    const struct dpif_netdev_impl_info_t *dpif_impls;
+    uint32_t count = dp_netdev_impl_get(&dpif_impls);
+    if (count == 0) {
+        unixctl_command_reply_error(conn, "error getting dpif names");
+        return;
+    }
+
+    /* Add all dpif functions to reply string. */
+    struct ds reply = DS_EMPTY_INITIALIZER;
+    ds_put_cstr(&reply, "Available DPIF implementations:\n");
+    for (uint32_t i = 0; i < count; i++) {
+        ds_put_format(&reply, "  %s\n", dpif_impls[i].name);
+    }
+    unixctl_command_reply(conn, ds_cstr(&reply));
+    ds_destroy(&reply);
+}
+
 static void
 dpif_netdev_impl_set(struct unixctl_conn *conn, int argc,
                      const char *argv[], void *aux OVS_UNUSED)
@@ -1290,6 +1311,9 @@  dpif_netdev_init(void)
                              "[dpif implementation name] [dp]",
                              1, 2, dpif_netdev_impl_set,
                              NULL);
+    unixctl_command_register("dpif-netdev/dpif-get", "",
+                             0, 0, dpif_netdev_impl_get,
+                             NULL);
     return 0;
 }