const struct dpif_class dpif_linux_class = {
"system",
dpif_linux_enumerate,
+ NULL,
dpif_linux_open,
dpif_linux_close,
dpif_linux_destroy,
return 0;
}
+static const char *
+dpif_netdev_port_open_type(const struct dpif_class *class, const char *type)
+{
+ return strcmp(type, "internal") ? type
+ : class != &dpif_netdev_class ? "dummy"
+ : "tap";
+}
+
static struct dpif *
create_dpif_netdev(struct dp_netdev *dp)
{
/* XXX reject devices already in some dp_netdev. */
/* Open and validate network device. */
- open_type = (strcmp(type, "internal") ? type
- : dp->class != &dpif_netdev_class ? "dummy"
- : "tap");
+ open_type = dpif_netdev_port_open_type(dp->class, type);
error = netdev_open(devname, open_type, &netdev);
if (error) {
return error;
const struct dpif_class dpif_netdev_class = {
"netdev",
dpif_netdev_enumerate,
+ dpif_netdev_port_open_type,
dpif_netdev_open,
dpif_netdev_close,
dpif_netdev_destroy,
* case this function may be a null pointer. */
int (*enumerate)(struct sset *all_dps);
+ /* Returns the type to pass to netdev_open() when a dpif of class
+ * 'dpif_class' has a port of type 'type', for a few special cases
+ * when a netdev type differs from a port type. For example, when
+ * using the userspace datapath, a port of type "internal" needs to
+ * be opened as "tap".
+ *
+ * Returns either 'type' itself or a string literal, which must not
+ * be freed. */
+ const char *(*port_open_type)(const struct dpif_class *dpif_class,
+ const char *type);
+
/* Attempts to open an existing dpif called 'name', if 'create' is false,
* or to open an existing dpif or create a new one, if 'create' is true.
*
return error;
}
+const char *
+dpif_port_open_type(const char *datapath_type, const char *port_type)
+{
+ struct registered_dpif_class *registered_class;
+
+ datapath_type = dpif_normalize_type(datapath_type);
+
+ registered_class = shash_find_data(&dpif_classes, datapath_type);
+ if (!registered_class
+ || !registered_class->dpif_class->port_open_type) {
+ return port_type;
+ }
+
+ return registered_class->dpif_class->port_open_type(
+ registered_class->dpif_class, port_type);
+}
+
/* Attempts to add 'netdev' as a port on 'dpif'. If 'port_nop' is
* non-null and its value is not UINT32_MAX, then attempts to use the
* value as the port number.
\f
/* Port operations. */
+const char *dpif_port_open_type(const char *datapath_type,
+ const char *port_type);
int dpif_port_add(struct dpif *, struct netdev *, uint32_t *port_nop);
int dpif_port_del(struct dpif *, uint32_t port_no);
return error;
}
\f
+static const char *
+port_open_type(const char *datapath_type, const char *port_type)
+{
+ return dpif_port_open_type(datapath_type, port_type);
+}
+
/* Type functions. */
static int
enumerate_types,
enumerate_names,
del,
+ port_open_type,
type_run,
type_run_fast,
type_wait,
*/
int (*del)(const char *type, const char *name);
+ /* Returns the type to pass to netdev_open() when a datapath of type
+ * 'datapath_type' has a port of type 'port_type', for a few special
+ * cases when a netdev type differs from a port type. For example,
+ * when using the userspace datapath, a port of type "internal"
+ * needs to be opened as "tap".
+ *
+ * Returns either 'type' itself or a string literal, which must not
+ * be freed. */
+ const char *(*port_open_type)(const char *datapath_type,
+ const char *port_type);
+
/* ## ------------------------ ## */
/* ## Top-Level type Functions ## */
/* ## ------------------------ ## */
return dump->error == EOF ? 0 : dump->error;
}
+/* Returns the type to pass to netdev_open() when a datapath of type
+ * 'datapath_type' has a port of type 'port_type', for a few special
+ * cases when a netdev type differs from a port type. For example, when
+ * using the userspace datapath, a port of type "internal" needs to be
+ * opened as "tap".
+ *
+ * Returns either 'type' itself or a string literal, which must not be
+ * freed. */
+const char *
+ofproto_port_open_type(const char *datapath_type, const char *port_type)
+{
+ const struct ofproto_class *class;
+
+ datapath_type = ofproto_normalize_type(datapath_type);
+ class = ofproto_class_find__(datapath_type);
+ if (!class) {
+ return port_type;
+ }
+
+ return (class->port_open_type
+ ? class->port_open_type(datapath_type, port_type)
+ : port_type);
+}
+
/* Attempts to add 'netdev' as a port on 'ofproto'. If 'ofp_portp' is
* non-null and '*ofp_portp' is not OFPP_NONE, attempts to use that as
* the port's OpenFlow port number.
#define OFPROTO_FLOW_EVICTION_THRESHOLD_DEFAULT 1000
#define OFPROTO_FLOW_EVICTION_THRESHOLD_MIN 100
+const char *ofproto_port_open_type(const char *datapath_type,
+ const char *port_type);
int ofproto_port_add(struct ofproto *, struct netdev *, uint16_t *ofp_portp);
int ofproto_port_del(struct ofproto *, uint16_t ofp_port);
int ofproto_port_get_stats(const struct ofport *, struct netdev_stats *stats);