#include "tnl-ports.h"
#include "util.h"
#include "valgrind.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
VLOG_DEFINE_THIS_MODULE(dpif);
return error;
}
+/* Attempts to install 'key' into the datapath, fetches it, then deletes it.
+ * Returns true if the datapath supported installing 'flow', false otherwise.
+ */
+bool
+dpif_probe_feature(struct dpif *dpif, const char *name,
+ const struct ofpbuf *key, const ovs_u128 *ufid)
+{
+ struct dpif_flow flow;
+ struct ofpbuf reply;
+ uint64_t stub[DPIF_FLOW_BUFSIZE / 8];
+ bool enable_feature = false;
+ int error;
+
+ /* Use DPIF_FP_MODIFY to cover the case where ovs-vswitchd is killed (and
+ * restarted) at just the right time such that feature probes from the
+ * previous run are still present in the datapath. */
+ error = dpif_flow_put(dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY | DPIF_FP_PROBE,
+ ofpbuf_data(key), ofpbuf_size(key), NULL, 0, NULL, 0,
+ ufid, NULL);
+ if (error) {
+ if (error != EINVAL) {
+ VLOG_WARN("%s: %s flow probe failed (%s)",
+ dpif_name(dpif), name, ovs_strerror(error));
+ }
+ return false;
+ }
+
+ ofpbuf_use_stack(&reply, &stub, sizeof stub);
+ error = dpif_flow_get(dpif, ofpbuf_data(key), ofpbuf_size(key), ufid,
+ &reply, &flow);
+ if (!error
+ && (!ufid || (flow.ufid_present && ovs_u128_equal(ufid, &flow.ufid)))) {
+ enable_feature = true;
+ }
+
+ error = dpif_flow_del(dpif, ofpbuf_data(key), ofpbuf_size(key), ufid,
+ NULL);
+ if (error) {
+ VLOG_WARN("%s: failed to delete %s feature probe flow",
+ dpif_name(dpif), name);
+ }
+
+ return enable_feature;
+}
+
/* A dpif_operate() wrapper for performing a single DPIF_OP_FLOW_GET. */
int
dpif_flow_get(struct dpif *dpif,
op.u.flow_get.flow = flow;
op.u.flow_get.flow->key = key;
op.u.flow_get.flow->key_len = key_len;
- op.u.flow_get.flow->ufid = *ufid;
opp = &op;
dpif_operate(dpif, &opp, 1);
op.u.flow_del.key_len = key_len;
op.u.flow_del.ufid = ufid;
op.u.flow_del.stats = stats;
+ op.u.flow_del.terse = false;
opp = &op;
dpif_operate(dpif, &opp, 1);
}
/* Creates and returns a new 'struct dpif_flow_dump' for iterating through the
- * flows in 'dpif'.
+ * flows in 'dpif'. If 'terse' is true, then only UFID and statistics will
+ * be returned in the dump. Otherwise, all fields will be returned.
*
* This function always successfully returns a dpif_flow_dump. Error
* reporting is deferred to dpif_flow_dump_destroy(). */
struct dpif_flow_dump *
-dpif_flow_dump_create(const struct dpif *dpif)
+dpif_flow_dump_create(const struct dpif *dpif, bool terse)
{
- return dpif->dpif_class->flow_dump_create(dpif);
+ return dpif->dpif_class->flow_dump_create(dpif, terse);
}
/* Destroys 'dump', which must have been created with dpif_flow_dump_create().