From: Billy O'Mahony <billy.o.mah...@intel.com>

At startup enumerate datapath and port types and add this information to
the datapath_types and port_types columns in the ovsdb.

This allows an ovsdb client to query the datapath in order to determine
if certain datapath and port types exist. For example, by querying the
port_types column, an ovsdb client will be able to determine if this
instance of ovs-vswitchd was compiled with DPDK support.

Signed-off-by: Mark D. Gray <mark.d.g...@intel.com>
Signed-off-by: Billy O'Mahony <billy.o.mah...@intel.com>
---
 lib/dpif-netdev.c          |    9 +++++-
 vswitchd/bridge.c          |   72 +++++++++++++++++++++++++++++++++++++++++++-
 vswitchd/vswitch.ovsschema |   12 +++++--
 vswitchd/vswitch.xml       |   18 +++++++++++
 4 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index f01fecb..3d8e04e 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -3547,7 +3547,10 @@ static bool
 dpcls_lookup(const struct dpcls *cls, const struct netdev_flow_key keys[],
              struct dpcls_rule **rules, const size_t cnt)
 {
-    /* The batch size 16 was experimentally found faster than 8 or 32. */
+    /* Process 'keys' in batch. Each of 'cnt' 'keys' are represented by 1
+     * bit in bitmask defined in 'maps' below.
+     *
+     * The batch size 16 was experimentally found faster than 8 or 32. */
     typedef uint16_t map_type;
 #define MAP_BITS (sizeof(map_type) * CHAR_BIT)
 
@@ -3559,6 +3562,8 @@ dpcls_lookup(const struct dpcls *cls, const struct 
netdev_flow_key keys[],
     map_type maps[N_MAPS];
     struct dpcls_subtable *subtable;
 
+    /* Initially set all bits to 1 but clear last couple of bits if 'cnt'
+     * is not a multiple of the batch size */
     memset(maps, 0xff, sizeof maps);
     if (cnt % MAP_BITS) {
         maps[N_MAPS - 1] >>= MAP_BITS - cnt % MAP_BITS; /* Clear extra bits. */
@@ -3573,6 +3578,8 @@ dpcls_lookup(const struct dpcls *cls, const struct 
netdev_flow_key keys[],
 
         BUILD_ASSERT_DECL(sizeof remains == sizeof *maps);
 
+        /* Iterate over 'mkeys' and 'mrules' in 'N_MAPS' batches of
+         * 'MAP_BITS'*/
         for (m = 0; m < N_MAPS; m++, mkeys += MAP_BITS, mrules += MAP_BITS) {
             uint32_t hashes[MAP_BITS];
             const struct cmap_node *nodes[MAP_BITS];
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 68648b9..3dc0f81 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -14,18 +14,20 @@
  */
 
 #include <config.h>
-#include "bridge.h"
 #include <errno.h>
 #include <inttypes.h>
 #include <stdlib.h>
+
 #include "async-append.h"
 #include "bfd.h"
 #include "bitmap.h"
+#include "bridge.h"
 #include "cfm.h"
 #include "connectivity.h"
 #include "coverage.h"
 #include "daemon.h"
 #include "dirs.h"
+#include "dpif.h"
 #include "dynamic-string.h"
 #include "hash.h"
 #include "hmap.h"
@@ -317,6 +319,7 @@ static ofp_port_t iface_get_requested_ofp_port(
     const struct ovsrec_interface *);
 static ofp_port_t iface_pick_ofport(const struct ovsrec_interface *);
 
+
 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
  *
  * This is deprecated.  It is only for compatibility with broken device drivers
@@ -335,6 +338,8 @@ static void add_vlan_splinter_ports(struct bridge *,
                                     const unsigned long int *splinter_vlans,
                                     struct shash *ports);
 
+static void discover_types(const struct ovsrec_open_vswitch *cfg);
+
 static void
 bridge_init_ofproto(const struct ovsrec_open_vswitch *cfg)
 {
@@ -394,6 +399,8 @@ bridge_init(const char *remote)
 
     ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_cur_cfg);
     ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_statistics);
+    ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_datapath_types);
+    ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_port_types);
     ovsdb_idl_omit(idl, &ovsrec_open_vswitch_col_external_ids);
     ovsdb_idl_omit(idl, &ovsrec_open_vswitch_col_ovs_version);
     ovsdb_idl_omit(idl, &ovsrec_open_vswitch_col_db_version);
@@ -2860,6 +2867,7 @@ void
 bridge_run(void)
 {
     static struct ovsrec_open_vswitch null_cfg;
+    static bool types_discovered;
     const struct ovsrec_open_vswitch *cfg;
 
     bool vlan_splinters_changed;
@@ -2889,6 +2897,11 @@ bridge_run(void)
     }
     cfg = ovsrec_open_vswitch_first(idl);
 
+    if (OVS_UNLIKELY(!types_discovered && cfg)) {
+        discover_types(cfg);
+        types_discovered = true;
+    }
+
     /* Initialize the ofproto library.  This only needs to run once, but
      * it must be done after the configuration is set.  If the
      * initialization has already occurred, bridge_init_ofproto()
@@ -5023,3 +5036,60 @@ mirror_refresh_stats(struct mirror *m)
 
     ovsrec_mirror_set_statistics(m->cfg, keys, values, stat_cnt);
 }
+
+/*
+ * Add registered netdev and dpif types to ovsdb to allow external
+ * applications to query the capabilities of the Open vSwitch instance
+ * running on the node.
+ */
+static void
+discover_types(const struct ovsrec_open_vswitch *cfg)
+{
+    struct sset types;
+    const char *type;
+    struct ovsdb_idl_txn *txn;
+    size_t n_dp_types, n_port_types;
+    unsigned int i;
+    const char **datapath_types;
+    const char **port_types;
+
+    txn = ovsdb_idl_txn_create(idl);
+
+    /* datapath types */
+    sset_init(&types);
+    dp_enumerate_types(&types);
+    n_dp_types = sset_count(&types);
+
+    datapath_types = xmalloc((sizeof *datapath_types) * n_dp_types);
+
+    i = 0;
+    SSET_FOR_EACH(type, &types) {
+        datapath_types[i++] = type;
+    }
+
+    ovsrec_open_vswitch_set_datapath_types(cfg, datapath_types, n_dp_types);
+
+    sset_destroy(&types);
+
+    /* port types */
+    sset_init(&types);
+    netdev_enumerate_types(&types);
+    n_port_types = sset_count(&types);
+
+    port_types = xmalloc((sizeof *port_types) * n_port_types);
+
+    i = 0;
+    SSET_FOR_EACH(type, &types) {
+        port_types[i++] = type;
+    }
+
+    ovsrec_open_vswitch_set_port_types(cfg, port_types, n_port_types);
+    sset_destroy(&types);
+
+    /* clean up any allocated memory */
+    free(datapath_types);
+    free(port_types);
+
+    ovsdb_idl_txn_commit(txn);
+    ovsdb_idl_txn_destroy(txn);
+}
diff --git a/vswitchd/vswitch.ovsschema b/vswitchd/vswitch.ovsschema
index 4898b16..ee7761c 100644
--- a/vswitchd/vswitch.ovsschema
+++ b/vswitchd/vswitch.ovsschema
@@ -1,6 +1,6 @@
 {"name": "Open_vSwitch",
- "version": "7.11.2",
- "cksum": "320332148 22294",
+ "version": "7.12.1",
+ "cksum": "2836575742 22534",
  "tables": {
    "Open_vSwitch": {
      "columns": {
@@ -39,7 +39,13 @@
                   "min": 0, "max": 1}},
        "system_version": {
          "type": {"key": {"type": "string"},
-                  "min": 0, "max": 1}}},
+                  "min": 0, "max": 1}},
+       "datapath_types": {
+         "type": {"key": {"type": "string"},
+                  "min": 0, "max": "unlimited"}},
+       "port_types": {
+         "type": {"key": {"type": "string"},
+                  "min": 0, "max": "unlimited"}}},
      "isRoot": true,
      "maxRows": 1},
    "Bridge": {
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 1bd6522..6300d4e 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -423,6 +423,24 @@
 
     </group>
 
+    <group title="Capabilities">
+      <p>
+        These columns report capabilities of the Open vSwitch instance. Any
+        value reported in these columns should be detected from probing Open
+        vSwitch.
+      </p>
+      <column name="datapath_types">
+        <p>
+          This column reports the different dpifs registered with the system.
+        </p>
+      </column>
+      <column name="port_types">
+        <p>
+          This column reports the different netdevs registered with the system.
+        </p>
+      </column>
+    </group>
+
     <group title="Database Configuration">
       <p>
         These columns primarily configure the Open vSwitch database
-- 
1.7.4.1

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to