+ expired.flow = facet->flow;
+ expired.packet_count = facet->packet_count;
+ expired.byte_count = facet->byte_count;
+ expired.used = facet->used;
+ netflow_expire(ofproto->netflow, &facet->nf_flow, &expired);
+ }
+
+ facet->rule->packet_count += facet->packet_count;
+ facet->rule->byte_count += facet->byte_count;
+
+ /* Reset counters to prevent double counting if 'facet' ever gets
+ * reinstalled. */
+ facet->packet_count = 0;
+ facet->byte_count = 0;
+ facet->accounted_bytes = 0;
+
+ netflow_flow_clear(&facet->nf_flow);
+}
+
+/* Searches 'ofproto''s table of facets for one exactly equal to 'flow'.
+ * Returns it if found, otherwise a null pointer.
+ *
+ * The returned facet might need revalidation; use facet_lookup_valid()
+ * instead if that is important. */
+static struct facet *
+facet_find(struct ofproto *ofproto, const struct flow *flow)
+{
+ struct facet *facet;
+
+ HMAP_FOR_EACH_WITH_HASH (facet, hmap_node, flow_hash(flow, 0),
+ &ofproto->facets) {
+ if (flow_equal(flow, &facet->flow)) {
+ return facet;
+ }
+ }
+
+ return NULL;
+}
+
+/* Searches 'ofproto''s table of facets for one exactly equal to 'flow'.
+ * Returns it if found, otherwise a null pointer.
+ *
+ * The returned facet is guaranteed to be valid. */
+static struct facet *
+facet_lookup_valid(struct ofproto *ofproto, const struct flow *flow)
+{
+ struct facet *facet = facet_find(ofproto, flow);
+
+ /* The facet we found might not be valid, since we could be in need of
+ * revalidation. If it is not valid, don't return it. */
+ if (facet
+ && ofproto->need_revalidate
+ && !facet_revalidate(ofproto, facet)) {
+ COVERAGE_INC(ofproto_invalidated);
+ return NULL;
+ }
+
+ return facet;
+}
+
+/* Re-searches 'ofproto''s classifier for a rule matching 'facet':
+ *
+ * - If the rule found is different from 'facet''s current rule, moves
+ * 'facet' to the new rule and recompiles its actions.
+ *
+ * - If the rule found is the same as 'facet''s current rule, leaves 'facet'
+ * where it is and recompiles its actions anyway.
+ *
+ * - If there is none, destroys 'facet'.
+ *
+ * Returns true if 'facet' still exists, false if it has been destroyed. */
+static bool
+facet_revalidate(struct ofproto *ofproto, struct facet *facet)
+{
+ struct rule *new_rule;
+ struct odp_actions a;
+ size_t actions_len;
+ uint16_t new_nf_output_iface;
+ bool actions_changed;
+
+ COVERAGE_INC(facet_revalidate);
+
+ /* Determine the new rule. */
+ new_rule = rule_lookup(ofproto, &facet->flow);
+ if (!new_rule) {
+ /* No new rule, so delete the facet. */
+ facet_remove(ofproto, facet);
+ return false;