vswitch.ovsschema: Add datapath_types and port_types.
authorMark D. Gray <mark.d.gray@intel.com>
Tue, 24 Mar 2015 10:39:11 +0000 (10:39 +0000)
committerBen Pfaff <blp@nicira.com>
Tue, 24 Mar 2015 16:12:27 +0000 (09:12 -0700)
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.gray@intel.com>
Signed-off-by: Billy O'Mahony <billy.o.mahony@intel.com>
[blp@nicira.com made several changes]
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/sset.c
lib/sset.h
vswitchd/bridge.c
vswitchd/vswitch.ovsschema
vswitchd/vswitch.xml

index 443538d..33c4298 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2011, 2012, 2013, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -269,21 +269,12 @@ sset_at_position(const struct sset *set, uint32_t *bucketp, uint32_t *offsetp)
     return SSET_NODE_FROM_HMAP_NODE(hmap_node);
 }
 
-static int
-compare_string_pointers(const void *a_, const void *b_)
-{
-    const char *const *a = a_;
-    const char *const *b = b_;
-
-    return strcmp(*a, *b);
-}
-
-/* Returns a null-terminated array of pointers to the strings in 'set', sorted
- * alphabetically.  The caller must free the returned array when it is no
+/* Returns a null-terminated array of pointers to the strings in 'set', in no
+ * particular order.  The caller must free the returned array when it is no
  * longer needed, but the strings in the array belong to 'set' and thus must
  * not be modified or freed. */
 const char **
-sset_sort(const struct sset *set)
+sset_array(const struct sset *set)
 {
     size_t n = sset_count(set);
     const char **array;
@@ -298,7 +289,26 @@ sset_sort(const struct sset *set)
     ovs_assert(i == n);
     array[n] = NULL;
 
-    qsort(array, n, sizeof *array, compare_string_pointers);
+    return array;
+}
+
+static int
+compare_string_pointers(const void *a_, const void *b_)
+{
+    const char *const *a = a_;
+    const char *const *b = b_;
+
+    return strcmp(*a, *b);
+}
 
+/* Returns a null-terminated array of pointers to the strings in 'set', sorted
+ * alphabetically.  The caller must free the returned array when it is no
+ * longer needed, but the strings in the array belong to 'set' and thus must
+ * not be modified or freed. */
+const char **
+sset_sort(const struct sset *set)
+{
+    const char **array = sset_array(set);
+    qsort(array, sset_count(set), sizeof *array, compare_string_pointers);
     return array;
 }
index 1e864ef..35bf463 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2011, 2012, 2013, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -80,6 +80,7 @@ struct sset_node *sset_at_position(const struct sset *,
           : false);                                 \
          (NAME) = (NEXT))
 
+const char **sset_array(const struct sset *);
 const char **sset_sort(const struct sset *);
 \f
 /* Implementation helper macros. */
index 4213a79..2e90ea2 100644 (file)
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <stdlib.h>
+
 #include "async-append.h"
 #include "bfd.h"
 #include "bitmap.h"
@@ -26,6 +27,7 @@
 #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_iface_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);
@@ -571,6 +578,10 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
         smap_get_int(&ovs_cfg->other_config, "n-handler-threads", 0),
         smap_get_int(&ovs_cfg->other_config, "n-revalidator-threads", 0));
 
+    if (ovs_cfg) {
+        discover_types(ovs_cfg);
+    }
+
     /* Destroy "struct bridge"s, "struct port"s, and "struct iface"s according
      * to 'ovs_cfg', with only very minimal configuration otherwise.
      *
@@ -2940,6 +2951,7 @@ bridge_run(void)
 
         if (cfg) {
             ovsrec_open_vswitch_set_cur_cfg(cfg, cfg->next_cfg);
+            discover_types(cfg);
         }
 
         /* If we are completing our initial configuration for this run
@@ -5023,3 +5035,31 @@ 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;
+
+    /* Datapath types. */
+    sset_init(&types);
+    dp_enumerate_types(&types);
+    const char **datapath_types = sset_array(&types);
+    ovsrec_open_vswitch_set_datapath_types(cfg, datapath_types,
+                                           sset_count(&types));
+    free(datapath_types);
+    sset_destroy(&types);
+
+    /* Port types. */
+    sset_init(&types);
+    netdev_enumerate_types(&types);
+    const char **iface_types = sset_array(&types);
+    ovsrec_open_vswitch_set_iface_types(cfg, iface_types, sset_count(&types));
+    free(iface_types);
+    sset_destroy(&types);
+}
index 4898b16..35f145f 100644 (file)
@@ -1,6 +1,6 @@
 {"name": "Open_vSwitch",
- "version": "7.11.2",
- "cksum": "320332148 22294",
+ "version": "7.12.1",
+ "cksum": "2211824403 22535",
  "tables": {
    "Open_vSwitch": {
      "columns": {
                   "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"}},
+       "iface_types": {
+         "type": {"key": {"type": "string"},
+                  "min": 0, "max": "unlimited"}}},
      "isRoot": true,
      "maxRows": 1},
    "Bridge": {
index 07f3bea..e04aefc 100644 (file)
 
     </group>
 
+    <group title="Capabilities">
+      <p>
+        These columns report capabilities of the Open vSwitch instance.
+      </p>
+      <column name="datapath_types">
+        <p>
+          This column reports the different dpifs registered with the system.
+          These are the values that this instance supports in the <ref
+          column="datapath_type" table="Bridge"/> column of the <ref
+          table="Bridge"/> table.
+        </p>
+      </column>
+      <column name="iface_types">
+        <p>
+          This column reports the different netdevs registered with the system.
+          These are the values that this instance supports in the <ref
+          column="type" table="Interface"/> column of the <ref
+          table="Interface"/> table.
+        </p>
+      </column>
+    </group>
+
     <group title="Database Configuration">
       <p>
         These columns primarily configure the Open vSwitch database
 
     <group title="Other Features">
       <column name="datapath_type">
-        Name of datapath provider.  The kernel datapath has
-        type <code>system</code>.  The userspace datapath has
-        type <code>netdev</code>.
+        Name of datapath provider.  The kernel datapath has type
+        <code>system</code>.  The userspace datapath has type
+        <code>netdev</code>.  A manager may refer to the <ref
+        table="Open_vSwitch" column="datapath_types"/> column of the <ref
+        table="Open_vSwitch"/> table for a list of the types accepted by this
+        Open vSwitch instance.
       </column>
 
       <column name="external_ids" key="bridge-id">
     <group title="System-Specific Details">
       <column name="type">
         <p>
-          The interface type, one of:
+          The interface type.  The types supported by a particular instance of
+          Open vSwitch are listed in the <ref table="Open_vSwitch"
+          column="iface_types"/> column in the <ref table="Open_vSwitch"/>
+          table.  The following types are defined:
         </p>
 
         <dl>