X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fdpif.c;h=18ef790afac4d74abad7651e21166fa67b826848;hb=85b20fd6ee585f462e012fbcc7f966a81edab2ed;hp=d8ca0617329cbed91393b2ad1411b7bbbaf76765;hpb=9b56fe137d3c734edcfa00631a960920f04c866a;p=sliver-openvswitch.git diff --git a/lib/dpif.c b/lib/dpif.c index d8ca06173..18ef790af 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -62,6 +62,7 @@ static const struct dpif_class *base_dpif_classes[] = { &dpif_linux_class, #endif &dpif_netdev_class, + &dpif_planetlab_class, }; struct registered_dpif_class { @@ -372,6 +373,13 @@ dpif_base_name(const struct dpif *dpif) return dpif->base_name; } +/* Returns the type of datapath 'dpif'. */ +const char * +dpif_type(const struct dpif *dpif) +{ + return dpif->dpif_class->type; +} + /* Returns the fully spelled out name for the given datapath 'type'. * * Normalized type string can be compared with strcmp(). Unnormalized type @@ -410,6 +418,23 @@ dpif_get_dp_stats(const struct dpif *dpif, struct dpif_dp_stats *stats) 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. @@ -486,6 +511,20 @@ dpif_port_destroy(struct dpif_port *dpif_port) free(dpif_port->type); } +/* Checks if port named 'devname' exists in 'dpif'. If so, returns + * true; otherwise, returns false. */ +bool +dpif_port_exists(const struct dpif *dpif, const char *devname) +{ + int error = dpif->dpif_class->port_query_by_name(dpif, devname, NULL); + if (error != 0 && error != ENOENT && error != ENODEV) { + VLOG_WARN_RL(&error_rl, "%s: failed to query port %s: %s", + dpif_name(dpif), devname, strerror(error)); + } + + return !error; +} + /* Looks up port number 'port_no' in 'dpif'. On success, returns 0 and * initializes '*port' appropriately; on failure, returns a positive errno * value.