const struct flow *, bool clone);
struct ofproto {
+ char *name; /* Datapath name. */
+ struct hmap_node hmap_node; /* In global 'all_ofprotos' hmap. */
+
/* Settings. */
uint64_t datapath_id; /* Datapath ID. */
uint64_t fallback_dpid; /* Datapath ID if no better choice found. */
};
/* Map from dpif name to struct ofproto, for use by unixctl commands. */
-static struct shash all_ofprotos = SHASH_INITIALIZER(&all_ofprotos);
+static struct hmap all_ofprotos = HMAP_INITIALIZER(&all_ofprotos);
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
/* Initialize settings. */
p = xzalloc(sizeof *p);
+ p->name = xstrdup(dpif_name(dpif));
+ hmap_insert(&all_ofprotos, &p->hmap_node, hash_string(p->name, 0));
p->fallback_dpid = pick_fallback_dpid();
p->datapath_id = p->fallback_dpid;
p->mfr_desc = xstrdup(DEFAULT_MFR_DESC);
p->datapath_id = pick_datapath_id(p);
VLOG_INFO("using datapath ID %016"PRIx64, p->datapath_id);
- shash_add_once(&all_ofprotos, dpif_name(p->dpif), p);
-
/* Initialize OpenFlow connections. */
p->connmgr = connmgr_create(p, datapath, local_name);
ofport = get_port(ofproto, port_no);
if (!ofport) {
VLOG_WARN("%s: cannot configure CFM on nonexistent port %"PRIu32,
- dpif_name(ofproto->dpif), port_no);
+ ofproto->name, port_no);
return;
}
if (!cfm_configure(ofport->cfm)) {
VLOG_WARN("%s: CFM configuration on port %"PRIu32" (%s) failed",
- dpif_name(ofproto->dpif), port_no,
+ ofproto->name, port_no,
netdev_get_name(ofport->netdev));
cfm_destroy(ofport->cfm);
ofport->cfm = NULL;
return;
}
- shash_find_and_delete(&all_ofprotos, dpif_name(p->dpif));
+ hmap_remove(&all_ofprotos, &p->hmap_node);
ofproto_flush_flows__(p);
connmgr_destroy(p->connmgr);
int error = dpif_delete(p->dpif);
if (error && error != ENOENT) {
VLOG_ERR("bridge %s: failed to destroy (%s)",
- dpif_name(p->dpif), strerror(error));
+ p->name, strerror(error));
}
}
dpif_close(p->dpif);
hmap_destroy(&p->ports);
+ free(p->name);
free(p);
}
* spin from here on out. */
static struct vlog_rate_limit rl2 = VLOG_RATE_LIMIT_INIT(1, 5);
VLOG_ERR_RL(&rl2, "%s: datapath was destroyed externally",
- dpif_name(p->dpif));
+ p->name);
return ENODEV;
}
break;
error = dpif_port_del(ofproto->dpif, odp_port);
if (error) {
VLOG_ERR("%s: failed to remove port %"PRIu16" (%s) interface (%s)",
- dpif_name(ofproto->dpif), odp_port, name, strerror(error));
+ ofproto->name, odp_port, name, strerror(error));
} else if (ofport) {
/* 'name' is the netdev's name and update_port() is going to close the
* netdev. Just in case update_port() refers to 'name' after it
if (error) {
VLOG_WARN_RL(&rl, "%s: failed to send packet on port %"PRIu32" (%s)",
- dpif_name(ofproto->dpif), port_no, strerror(error));
+ ofproto->name, port_no, strerror(error));
}
return error;
}
ds_put_format(&s, " %d:%d", i * BUCKET_WIDTH, buckets[i]);
}
}
- VLOG_INFO("%s: %s (msec:count)",
- dpif_name(ofproto->dpif), ds_cstr(&s));
+ VLOG_INFO("%s: %s (msec:count)", ofproto->name, ds_cstr(&s));
ds_destroy(&s);
}
return eth_addr_to_uint64(ea);
}
\f
+static struct ofproto *
+ofproto_lookup(const char *name)
+{
+ struct ofproto *ofproto;
+
+ HMAP_FOR_EACH_WITH_HASH (ofproto, hmap_node, hash_string(name, 0),
+ &all_ofprotos) {
+ if (!strcmp(ofproto->name, name)) {
+ return ofproto;
+ }
+ }
+ return NULL;
+}
+
static void
ofproto_unixctl_list(struct unixctl_conn *conn, const char *arg OVS_UNUSED,
void *aux OVS_UNUSED)
{
- const struct shash_node *node;
+ struct ofproto *ofproto;
struct ds results;
ds_init(&results);
- SHASH_FOR_EACH (node, &all_ofprotos) {
- ds_put_format(&results, "%s\n", node->name);
+ HMAP_FOR_EACH (ofproto, hmap_node, &all_ofprotos) {
+ ds_put_format(&results, "%s\n", ofproto->name);
}
unixctl_command_reply(conn, 200, ds_cstr(&results));
ds_destroy(&results);
goto exit;
}
- ofproto = shash_find_data(&all_ofprotos, dpname);
+ ofproto = ofproto_lookup(dpname);
if (!ofproto) {
unixctl_command_reply(conn, 501, "Unknown ofproto (use ofproto/list "
"for help)");