[ovs-dev] [PATCH 3/3] bridge: Update bridge to discover datapath and port types

Mark D. Gray mark.d.gray at intel.com
Fri Mar 6 15:37:38 UTC 2015


From: "Mark D. Gray" <mark.d.gray at intel.com>

This patch enumerates datapath and port types and adds 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 at intel.com>
---
 vswitchd/bridge.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 1 deletion(-)

diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index dd622dc..58cf27c 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);
@@ -2889,6 +2896,9 @@ bridge_run(void)
     }
     cfg = ovsrec_open_vswitch_first(idl);
 
+    if (cfg)
+        discover_types(cfg);
+
     /* 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 +5033,67 @@ 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(char *) * n_dp_types);
+
+    i = 0;
+    SSET_FOR_EACH(type, &types) {
+        datapath_types[i++] = xstrdup(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(char *) * n_port_types);
+
+    i = 0;
+    SSET_FOR_EACH(type, &types) {
+        port_types[i++] = xstrdup(type);
+    }
+
+    ovsrec_open_vswitch_set_port_types(cfg, port_types, n_port_types);
+    sset_destroy(&types);
+
+    /* clean up any allocated memory */
+    for (i = 0; i < n_dp_types; i++) {
+         free((char *)datapath_types[i]);
+    }
+
+    free(datapath_types);
+    for (i = 0; i < n_port_types; i++) {
+         free((char *)port_types[i]);
+    }
+    free(port_types);
+
+    ovsdb_idl_txn_commit(txn);
+    ovsdb_idl_txn_destroy(txn);
+}
-- 
1.9.3




More information about the dev mailing list