meta-flow: New "subfield" data structure.
[sliver-openvswitch.git] / ofproto / ofproto-dpif.c
index 93403ba..a0c7b28 100644 (file)
@@ -34,6 +34,7 @@
 #include "lacp.h"
 #include "learn.h"
 #include "mac-learning.h"
+#include "meta-flow.h"
 #include "multipath.h"
 #include "netdev.h"
 #include "netlink.h"
@@ -1193,7 +1194,7 @@ update_stp_port_state(struct ofport_dpif *ofport)
         if (stp_learn_in_state(ofport->stp_state)
                 != stp_learn_in_state(state)) {
             /* xxx Learning action flows should also be flushed. */
-            mac_learning_flush(ofproto->ml);
+            mac_learning_flush(ofproto->ml, &ofproto->revalidate_set);
         }
         fwd_change = stp_forward_in_state(ofport->stp_state)
                         != stp_forward_in_state(state);
@@ -1296,6 +1297,10 @@ stp_run(struct ofproto_dpif *ofproto)
                 update_stp_port_state(ofport);
             }
         }
+
+        if (stp_check_and_reset_fdb_flush(ofproto->stp)) {
+            mac_learning_flush(ofproto->ml, &ofproto->revalidate_set);
+        }
     }
 }
 
@@ -1879,7 +1884,7 @@ bundle_run(struct ofbundle *bundle)
         }
 
         bond_run(bundle->bond, &bundle->ofproto->revalidate_set,
-                 lacp_negotiated(bundle->lacp));
+                 lacp_status(bundle->lacp));
         if (bond_should_send_learning_packets(bundle->bond)) {
             bundle_send_learning_packets(bundle);
         }
@@ -2064,7 +2069,7 @@ mirror_set(struct ofproto *ofproto_, void *aux,
     }
 
     ofproto->need_revalidate = true;
-    mac_learning_flush(ofproto->ml);
+    mac_learning_flush(ofproto->ml, &ofproto->revalidate_set);
     mirror_update_dups(ofproto);
 
     return 0;
@@ -2083,7 +2088,7 @@ mirror_destroy(struct ofmirror *mirror)
 
     ofproto = mirror->ofproto;
     ofproto->need_revalidate = true;
-    mac_learning_flush(ofproto->ml);
+    mac_learning_flush(ofproto->ml, &ofproto->revalidate_set);
 
     mirror_bit = MIRROR_MASK_C(1) << mirror->idx;
     HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
@@ -2126,8 +2131,7 @@ set_flood_vlans(struct ofproto *ofproto_, unsigned long *flood_vlans)
 {
     struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
     if (mac_learning_set_flood_vlans(ofproto->ml, flood_vlans)) {
-        ofproto->need_revalidate = true;
-        mac_learning_flush(ofproto->ml);
+        mac_learning_flush(ofproto->ml, &ofproto->revalidate_set);
     }
     return 0;
 }
@@ -2413,7 +2417,7 @@ struct flow_miss {
 };
 
 struct flow_miss_op {
-    union dpif_op dpif_op;
+    struct dpif_op dpif_op;
     struct subfacet *subfacet;
 };
 
@@ -2421,7 +2425,7 @@ struct flow_miss_op {
  * OpenFlow controller as necessary according to their individual
  * configurations. */
 static void
-send_packet_in_miss(struct ofproto_dpif *ofproto, struct ofpbuf *packet,
+send_packet_in_miss(struct ofproto_dpif *ofproto, const struct ofpbuf *packet,
                     const struct flow *flow)
 {
     struct ofputil_packet_in pin;
@@ -2548,7 +2552,6 @@ handle_flow_miss(struct ofproto_dpif *ofproto, struct flow_miss *miss,
         struct flow_miss_op *op;
         struct dpif_execute *execute;
 
-        list_remove(&packet->list_node);
         ofproto->n_matches++;
 
         if (facet->rule->up.cr.priority == FAIL_OPEN_PRIORITY) {
@@ -2572,6 +2575,11 @@ handle_flow_miss(struct ofproto_dpif *ofproto, struct flow_miss *miss,
         dpif_flow_stats_extract(&facet->flow, packet, &stats);
         subfacet_update_stats(subfacet, &stats);
 
+        if (!subfacet->actions_len) {
+            /* No actions to execute, so skip talking to the dpif. */
+            continue;
+        }
+
         if (flow->vlan_tci != subfacet->initial_tci) {
             /* This packet was received on a VLAN splinter port.  We added
              * a VLAN to the packet to make the packet resemble the flow,
@@ -2582,9 +2590,9 @@ handle_flow_miss(struct ofproto_dpif *ofproto, struct flow_miss *miss,
         }
 
         op = &ops[(*n_ops)++];
-        execute = &op->dpif_op.execute;
+        execute = &op->dpif_op.u.execute;
         op->subfacet = subfacet;
-        execute->type = DPIF_OP_EXECUTE;
+        op->dpif_op.type = DPIF_OP_EXECUTE;
         execute->key = miss->key;
         execute->key_len = miss->key_len;
         execute->actions = (facet->may_install
@@ -2597,10 +2605,10 @@ handle_flow_miss(struct ofproto_dpif *ofproto, struct flow_miss *miss,
 
     if (facet->may_install && subfacet->key_fitness != ODP_FIT_TOO_LITTLE) {
         struct flow_miss_op *op = &ops[(*n_ops)++];
-        struct dpif_flow_put *put = &op->dpif_op.flow_put;
+        struct dpif_flow_put *put = &op->dpif_op.u.flow_put;
 
         op->subfacet = subfacet;
-        put->type = DPIF_OP_FLOW_PUT;
+        op->dpif_op.type = DPIF_OP_FLOW_PUT;
         put->flags = DPIF_FP_CREATE | DPIF_FP_MODIFY;
         put->key = miss->key;
         put->key_len = miss->key_len;
@@ -2682,7 +2690,7 @@ handle_miss_upcalls(struct ofproto_dpif *ofproto, struct dpif_upcall *upcalls,
     struct dpif_upcall *upcall;
     struct flow_miss *miss, *next_miss;
     struct flow_miss_op flow_miss_ops[FLOW_MISS_MAX_BATCH * 2];
-    union dpif_op *dpif_ops[FLOW_MISS_MAX_BATCH * 2];
+    struct dpif_op *dpif_ops[FLOW_MISS_MAX_BATCH * 2];
     struct hmap todo;
     size_t n_ops;
     size_t i;
@@ -2734,14 +2742,10 @@ handle_miss_upcalls(struct ofproto_dpif *ofproto, struct dpif_upcall *upcalls,
     /* Process each element in the to-do list, constructing the set of
      * operations to batch. */
     n_ops = 0;
-    HMAP_FOR_EACH_SAFE (miss, next_miss, hmap_node, &todo) {
+    HMAP_FOR_EACH (miss, hmap_node, &todo) {
         handle_flow_miss(ofproto, miss, flow_miss_ops, &n_ops);
-        ofpbuf_list_delete(&miss->packets);
-        hmap_remove(&todo, &miss->hmap_node);
-        free(miss);
     }
     assert(n_ops <= ARRAY_SIZE(flow_miss_ops));
-    hmap_destroy(&todo);
 
     /* Execute batch. */
     for (i = 0; i < n_ops; i++) {
@@ -2753,25 +2757,28 @@ handle_miss_upcalls(struct ofproto_dpif *ofproto, struct dpif_upcall *upcalls,
     for (i = 0; i < n_ops; i++) {
         struct flow_miss_op *op = &flow_miss_ops[i];
         struct dpif_execute *execute;
-        struct dpif_flow_put *put;
 
         switch (op->dpif_op.type) {
         case DPIF_OP_EXECUTE:
-            execute = &op->dpif_op.execute;
+            execute = &op->dpif_op.u.execute;
             if (op->subfacet->actions != execute->actions) {
                 free((struct nlattr *) execute->actions);
             }
-            ofpbuf_delete((struct ofpbuf *) execute->packet);
             break;
 
         case DPIF_OP_FLOW_PUT:
-            put = &op->dpif_op.flow_put;
-            if (!put->error) {
+            if (!op->dpif_op.error) {
                 op->subfacet->installed = true;
             }
             break;
         }
     }
+    HMAP_FOR_EACH_SAFE (miss, next_miss, hmap_node, &todo) {
+        ofpbuf_list_delete(&miss->packets);
+        hmap_remove(&todo, &miss->hmap_node);
+        free(miss);
+    }
+    hmap_destroy(&todo);
 }
 
 static void
@@ -3364,6 +3371,7 @@ facet_check_consistency(struct facet *facet)
 
     struct rule_dpif *rule;
     struct subfacet *subfacet;
+    bool may_log = false;
     bool ok;
 
     /* Check the rule for consistency. */
@@ -3376,22 +3384,24 @@ facet_check_consistency(struct facet *facet)
         }
         return false;
     } else if (rule != facet->rule) {
-        struct ds s;
+        may_log = !VLOG_DROP_WARN(&rl);
+        ok = false;
+        if (may_log) {
+            struct ds s;
 
-        ds_init(&s);
-        flow_format(&s, &facet->flow);
-        ds_put_format(&s, ": facet associated with wrong rule (was "
-                      "table=%"PRIu8",", facet->rule->up.table_id);
-        cls_rule_format(&facet->rule->up.cr, &s);
-        ds_put_format(&s, ") (should have been table=%"PRIu8",",
-                      rule->up.table_id);
-        cls_rule_format(&rule->up.cr, &s);
-        ds_put_char(&s, ')');
-
-        VLOG_WARN("%s", ds_cstr(&s));
-        ds_destroy(&s);
+            ds_init(&s);
+            flow_format(&s, &facet->flow);
+            ds_put_format(&s, ": facet associated with wrong rule (was "
+                          "table=%"PRIu8",", facet->rule->up.table_id);
+            cls_rule_format(&facet->rule->up.cr, &s);
+            ds_put_format(&s, ") (should have been table=%"PRIu8",",
+                          rule->up.table_id);
+            cls_rule_format(&rule->up.cr, &s);
+            ds_put_char(&s, ')');
 
-        ok = false;
+            VLOG_WARN("%s", ds_cstr(&s));
+            ds_destroy(&s);
+        }
     } else {
         ok = true;
     }
@@ -3421,42 +3431,47 @@ facet_check_consistency(struct facet *facet)
                            || memcmp(subfacet->actions, odp_actions->data,
                                      subfacet->actions_len));
         if (should_install != subfacet->installed || actions_changed) {
-            struct odputil_keybuf keybuf;
-            struct ofpbuf key;
-            struct ds s;
+            if (ok) {
+                may_log = !VLOG_DROP_WARN(&rl);
+                ok = false;
+            }
 
-            ok = false;
+            if (may_log) {
+                struct odputil_keybuf keybuf;
+                struct ofpbuf key;
+                struct ds s;
 
-            ds_init(&s);
-            subfacet_get_key(subfacet, &keybuf, &key);
-            odp_flow_key_format(key.data, key.size, &s);
-
-            ds_put_cstr(&s, ": inconsistency in subfacet");
-            if (should_install != subfacet->installed) {
-                enum odp_key_fitness fitness = subfacet->key_fitness;
-
-                ds_put_format(&s, " (should%s have been installed)",
-                              should_install ? "" : " not");
-                ds_put_format(&s, " (may_set_up_flow=%s, fitness=%s)",
-                              ctx.may_set_up_flow ? "true" : "false",
-                              odp_key_fitness_to_string(fitness));
-            }
-            if (actions_changed) {
-                ds_put_cstr(&s, " (actions were: ");
-                format_odp_actions(&s, subfacet->actions,
-                                   subfacet->actions_len);
-                ds_put_cstr(&s, ") (correct actions: ");
-                format_odp_actions(&s, odp_actions->data,
-                                   odp_actions->size);
-                ds_put_char(&s, ')');
-            } else {
-                ds_put_cstr(&s, " (actions: ");
-                format_odp_actions(&s, subfacet->actions,
-                                   subfacet->actions_len);
-                ds_put_char(&s, ')');
+                ds_init(&s);
+                subfacet_get_key(subfacet, &keybuf, &key);
+                odp_flow_key_format(key.data, key.size, &s);
+
+                ds_put_cstr(&s, ": inconsistency in subfacet");
+                if (should_install != subfacet->installed) {
+                    enum odp_key_fitness fitness = subfacet->key_fitness;
+
+                    ds_put_format(&s, " (should%s have been installed)",
+                                  should_install ? "" : " not");
+                    ds_put_format(&s, " (may_set_up_flow=%s, fitness=%s)",
+                                  ctx.may_set_up_flow ? "true" : "false",
+                                  odp_key_fitness_to_string(fitness));
+                }
+                if (actions_changed) {
+                    ds_put_cstr(&s, " (actions were: ");
+                    format_odp_actions(&s, subfacet->actions,
+                                       subfacet->actions_len);
+                    ds_put_cstr(&s, ") (correct actions: ");
+                    format_odp_actions(&s, odp_actions->data,
+                                       odp_actions->size);
+                    ds_put_char(&s, ')');
+                } else {
+                    ds_put_cstr(&s, " (actions: ");
+                    format_odp_actions(&s, subfacet->actions,
+                                       subfacet->actions_len);
+                    ds_put_char(&s, ')');
+                }
+                VLOG_WARN("%s", ds_cstr(&s));
+                ds_destroy(&s);
             }
-            VLOG_WARN("%s", ds_cstr(&s));
-            ds_destroy(&s);
         }
 
     next:
@@ -4554,9 +4569,11 @@ static void
 xlate_output_reg_action(struct action_xlate_ctx *ctx,
                         const struct nx_action_output_reg *naor)
 {
+    struct mf_subfield src;
     uint64_t ofp_port;
 
-    ofp_port = nxm_read_field_bits(naor->src, naor->ofs_nbits, &ctx->flow);
+    nxm_decode(&src, naor->src, naor->ofs_nbits);
+    ofp_port = mf_get_subfield(&src, &ctx->flow);
 
     if (ofp_port <= UINT16_MAX) {
         xlate_output_action__(ctx, ofp_port, ntohs(naor->max_len));
@@ -5801,17 +5818,23 @@ ofproto_dpif_lookup(const char *name)
 }
 
 static void
-ofproto_unixctl_fdb_flush(struct unixctl_conn *conn, int argc OVS_UNUSED,
+ofproto_unixctl_fdb_flush(struct unixctl_conn *conn, int argc,
                           const char *argv[], void *aux OVS_UNUSED)
 {
-    const struct ofproto_dpif *ofproto;
+    struct ofproto_dpif *ofproto;
 
-    ofproto = ofproto_dpif_lookup(argv[1]);
-    if (!ofproto) {
-        unixctl_command_reply(conn, 501, "no such bridge");
-        return;
+    if (argc > 1) {
+        ofproto = ofproto_dpif_lookup(argv[1]);
+        if (!ofproto) {
+            unixctl_command_reply(conn, 501, "no such bridge");
+            return;
+        }
+        mac_learning_flush(ofproto->ml, &ofproto->revalidate_set);
+    } else {
+        HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
+            mac_learning_flush(ofproto->ml, &ofproto->revalidate_set);
+        }
     }
-    mac_learning_flush(ofproto->ml);
 
     unixctl_command_reply(conn, 200, "table successfully flushed");
 }
@@ -6111,8 +6134,8 @@ ofproto_dpif_unixctl_init(void)
     unixctl_command_register(
         "ofproto/trace",
         "bridge {tun_id in_port packet | odp_flow [-generate]}",
-        2, 4, ofproto_unixctl_trace, NULL);
-    unixctl_command_register("fdb/flush", "bridge", 1, 1,
+        2, 5, ofproto_unixctl_trace, NULL);
+    unixctl_command_register("fdb/flush", "[bridge]", 0, 1,
                              ofproto_unixctl_fdb_flush, NULL);
     unixctl_command_register("fdb/show", "bridge", 1, 1,
                              ofproto_unixctl_fdb_show, NULL);