[ovs-dev] [v10 07/15] dpif-netdev: Add command to get dpif implementations.

Cian Ferriter cian.ferriter at intel.com
Wed Apr 7 09:34:34 UTC 2021


From: Harry van Haaren <harry.van.haaren at intel.com>

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 at intel.com>
Signed-off-by: Cian Ferriter <cian.ferriter at 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 --git a/lib/dpif-netdev-private-dpif.c b/lib/dpif-netdev-private-dpif.c
index 28143c82c..545b36654 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 e6793364c..d1dae3d58 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 8e3d773d4..21c097b10 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -993,6 +993,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)
@@ -1291,6 +1312,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;
 }
 
-- 
2.17.1



More information about the dev mailing list