+ /* (Re)configure if necessary. */
+ database_changed = ovsdb_idl_run(idl);
+ cfg = ovsrec_open_vswitch_first(idl);
+#ifdef HAVE_OPENSSL
+ /* Re-configure SSL. We do this on every trip through the main loop,
+ * instead of just when the database changes, because the contents of the
+ * key and certificate files can change without the database changing.
+ *
+ * We do this before bridge_reconfigure() because that function might
+ * initiate SSL connections and thus requires SSL to be configured. */
+ if (cfg && cfg->ssl) {
+ const struct ovsrec_ssl *ssl = cfg->ssl;
+
+ stream_ssl_set_key_and_cert(ssl->private_key, ssl->certificate);
+ stream_ssl_set_ca_cert_file(ssl->ca_cert, ssl->bootstrap_ca_cert);
+ }
+#endif
+ if (database_changed || datapath_destroyed) {
+ if (cfg) {
+ struct ovsdb_idl_txn *txn = ovsdb_idl_txn_create(idl);
+
+ bridge_configure_once(cfg);
+ bridge_reconfigure(cfg);
+
+ ovsrec_open_vswitch_set_cur_cfg(cfg, cfg->next_cfg);
+ ovsdb_idl_txn_commit(txn);
+ ovsdb_idl_txn_destroy(txn); /* XXX */
+ } else {
+ /* We still need to reconfigure to avoid dangling pointers to
+ * now-destroyed ovsrec structures inside bridge data. */
+ static const struct ovsrec_open_vswitch null_cfg;
+
+ bridge_reconfigure(&null_cfg);
+ }
+ }
+
+ /* Refresh system and interface stats if necessary. */
+ if (time_msec() >= stats_timer) {
+ if (cfg) {
+ struct ovsdb_idl_txn *txn;
+
+ txn = ovsdb_idl_txn_create(idl);
+ LIST_FOR_EACH (br, node, &all_bridges) {
+ struct port *port;
+
+ HMAP_FOR_EACH (port, hmap_node, &br->ports) {
+ struct iface *iface;
+
+ LIST_FOR_EACH (iface, port_elem, &port->ifaces) {
+ iface_refresh_stats(iface);
+ iface_refresh_status(iface);
+ }
+ }
+ bridge_refresh_controller_status(br);
+ }
+ refresh_system_stats(cfg);
+ ovsdb_idl_txn_commit(txn);
+ ovsdb_idl_txn_destroy(txn); /* XXX */
+ }
+
+ stats_timer = time_msec() + STATS_INTERVAL;
+ }
+
+ if (time_msec() >= cfm_limiter) {
+ struct ovsdb_idl_txn *txn;
+ bool changed = false;
+
+ txn = ovsdb_idl_txn_create(idl);
+ LIST_FOR_EACH (br, node, &all_bridges) {
+ struct port *port;
+
+ HMAP_FOR_EACH (port, hmap_node, &br->ports) {
+ struct iface *iface;
+
+ LIST_FOR_EACH (iface, port_elem, &port->ifaces) {
+ changed = iface_refresh_cfm_stats(iface) || changed;
+ }
+ }
+ }
+
+ if (changed) {
+ cfm_limiter = time_msec() + CFM_LIMIT_INTERVAL;
+ }
+
+ ovsdb_idl_txn_commit(txn);
+ ovsdb_idl_txn_destroy(txn);
+ }
+}
+
+void
+bridge_wait(void)
+{
+ struct bridge *br;
+
+ LIST_FOR_EACH (br, node, &all_bridges) {
+ struct port *port;
+
+ ofproto_wait(br->ofproto);
+ mac_learning_wait(br->ml);
+ HMAP_FOR_EACH (port, hmap_node, &br->ports) {
+ port_wait(port);
+ }
+ }
+ ovsdb_idl_wait(idl);
+ poll_timer_wait_until(stats_timer);
+
+ if (cfm_limiter > time_msec()) {
+ poll_timer_wait_until(cfm_limiter);
+ }
+}
+
+/* Forces 'br' to revalidate all of its flows. This is appropriate when 'br''s
+ * configuration changes. */
+static void
+bridge_flush(struct bridge *br)
+{
+ COVERAGE_INC(bridge_flush);
+ br->flush = true;
+}
+\f
+/* Bridge unixctl user interface functions. */
+static void
+bridge_unixctl_fdb_show(struct unixctl_conn *conn,
+ const char *args, void *aux OVS_UNUSED)
+{
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ const struct bridge *br;
+ const struct mac_entry *e;
+
+ br = bridge_lookup(args);
+ if (!br) {
+ unixctl_command_reply(conn, 501, "no such bridge");
+ return;
+ }
+
+ ds_put_cstr(&ds, " port VLAN MAC Age\n");
+ LIST_FOR_EACH (e, lru_node, &br->ml->lrus) {
+ struct port *port = e->port.p;
+ ds_put_format(&ds, "%5d %4d "ETH_ADDR_FMT" %3d\n",
+ port_get_an_iface(port)->dp_ifidx,
+ e->vlan, ETH_ADDR_ARGS(e->mac), mac_entry_age(e));
+ }
+ unixctl_command_reply(conn, 200, ds_cstr(&ds));
+ ds_destroy(&ds);
+}
+\f
+/* CFM unixctl user interface functions. */
+static void
+cfm_unixctl_show(struct unixctl_conn *conn,
+ const char *args, void *aux OVS_UNUSED)
+{
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ struct iface *iface;
+ const struct cfm *cfm;
+
+ iface = iface_find(args);
+ if (!iface) {
+ unixctl_command_reply(conn, 501, "no such interface");
+ return;
+ }
+
+ cfm = ofproto_iface_get_cfm(iface->port->bridge->ofproto, iface->dp_ifidx);
+
+ if (!cfm) {
+ unixctl_command_reply(conn, 501, "CFM not enabled");
+ return;
+ }
+
+ cfm_dump_ds(cfm, &ds);
+ unixctl_command_reply(conn, 200, ds_cstr(&ds));
+ ds_destroy(&ds);
+}
+\f
+/* QoS unixctl user interface functions. */
+
+struct qos_unixctl_show_cbdata {
+ struct ds *ds;
+ struct iface *iface;
+};
+
+static void
+qos_unixctl_show_cb(unsigned int queue_id,
+ const struct shash *details,
+ void *aux)
+{
+ struct qos_unixctl_show_cbdata *data = aux;
+ struct ds *ds = data->ds;
+ struct iface *iface = data->iface;
+ struct netdev_queue_stats stats;
+ struct shash_node *node;
+ int error;
+
+ ds_put_cstr(ds, "\n");
+ if (queue_id) {
+ ds_put_format(ds, "Queue %u:\n", queue_id);
+ } else {
+ ds_put_cstr(ds, "Default:\n");
+ }
+
+ SHASH_FOR_EACH (node, details) {
+ ds_put_format(ds, "\t%s: %s\n", node->name, (char *)node->data);
+ }
+
+ error = netdev_get_queue_stats(iface->netdev, queue_id, &stats);
+ if (!error) {
+ if (stats.tx_packets != UINT64_MAX) {
+ ds_put_format(ds, "\ttx_packets: %"PRIu64"\n", stats.tx_packets);
+ }
+
+ if (stats.tx_bytes != UINT64_MAX) {
+ ds_put_format(ds, "\ttx_bytes: %"PRIu64"\n", stats.tx_bytes);
+ }
+
+ if (stats.tx_errors != UINT64_MAX) {
+ ds_put_format(ds, "\ttx_errors: %"PRIu64"\n", stats.tx_errors);
+ }
+ } else {
+ ds_put_format(ds, "\tFailed to get statistics for queue %u: %s",
+ queue_id, strerror(error));
+ }
+}
+
+static void
+qos_unixctl_show(struct unixctl_conn *conn,
+ const char *args, void *aux OVS_UNUSED)
+{
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ struct shash sh = SHASH_INITIALIZER(&sh);
+ struct iface *iface;
+ const char *type;
+ struct shash_node *node;
+ struct qos_unixctl_show_cbdata data;
+ int error;
+
+ iface = iface_find(args);
+ if (!iface) {
+ unixctl_command_reply(conn, 501, "no such interface");
+ return;
+ }
+
+ netdev_get_qos(iface->netdev, &type, &sh);
+
+ if (*type != '\0') {
+ ds_put_format(&ds, "QoS: %s %s\n", iface->name, type);
+
+ SHASH_FOR_EACH (node, &sh) {
+ ds_put_format(&ds, "%s: %s\n", node->name, (char *)node->data);
+ }
+
+ data.ds = &ds;
+ data.iface = iface;
+ error = netdev_dump_queues(iface->netdev, qos_unixctl_show_cb, &data);
+
+ if (error) {
+ ds_put_format(&ds, "failed to dump queues: %s", strerror(error));
+ }
+ unixctl_command_reply(conn, 200, ds_cstr(&ds));
+ } else {
+ ds_put_format(&ds, "QoS not configured on %s\n", iface->name);
+ unixctl_command_reply(conn, 501, ds_cstr(&ds));
+ }
+
+ shash_destroy_free_data(&sh);
+ ds_destroy(&ds);
+}
+\f
+/* Bridge reconfiguration functions. */
+static struct bridge *
+bridge_create(const struct ovsrec_bridge *br_cfg)
+{
+ struct bridge *br;
+ int error;
+
+ assert(!bridge_lookup(br_cfg->name));
+ br = xzalloc(sizeof *br);
+
+ error = dpif_create_and_open(br_cfg->name, br_cfg->datapath_type,
+ &br->dpif);
+ if (error) {