Fix "make dist" by adding forgotten files to sources lists.
[sliver-openvswitch.git] / switch / switch-flow.c
index cc462c0..82eee55 100644 (file)
@@ -37,8 +37,8 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
-#include "buffer.h"
-#include "openflow.h"
+#include "ofpbuf.h"
+#include "openflow/openflow.h"
 #include "packets.h"
 #include "timeval.h"
 
@@ -85,12 +85,13 @@ flow_matches_2wild(const struct sw_flow_key *a, const struct sw_flow_key *b)
 }
 
 /* Returns nonzero if 't' (the table entry's key) and 'd' (the key 
- * describing the deletion) match, that is, if their fields are 
+ * describing the match) match, that is, if their fields are 
  * equal modulo wildcards, zero otherwise.  If 'strict' is nonzero, the
  * wildcards must match in both 't_key' and 'd_key'.  Note that the
  * table's wildcards are ignored unless 'strict' is set. */
 int
-flow_del_matches(const struct sw_flow_key *t, const struct sw_flow_key *d, int strict)
+flow_matches_desc(const struct sw_flow_key *t, const struct sw_flow_key *d, 
+        int strict)
 {
     if (strict && d->wildcards != t->wildcards) {
         return 0;
@@ -128,7 +129,8 @@ flow_extract_match(struct sw_flow_key* to, const struct ofp_match* from)
              * protocol is unknown. */
             to->wildcards |= OFPFW_TP;
         } else if (from->nw_proto == IPPROTO_TCP 
-                || from->nw_proto == IPPROTO_UDP) {
+                || from->nw_proto == IPPROTO_UDP
+                || from->nw_proto == IPPROTO_ICMP) {
             to->flow.tp_src = from->tp_src;
             to->flow.tp_dst = from->tp_dst;
         } else {
@@ -166,22 +168,23 @@ flow_fill_match(struct ofp_match* to, const struct sw_flow_key* from)
     to->pad           = 0;
 }
 
-/* Allocates and returns a new flow with 'n_actions' action, using allocation
- * flags 'flags'.  Returns the new flow or a null pointer on failure. */
+/* Allocates and returns a new flow with room for 'actions_len' actions. 
+ * Returns the new flow or a null pointer on failure. */
 struct sw_flow *
-flow_alloc(int n_actions)
+flow_alloc(size_t actions_len)
 {
     struct sw_flow_actions *sfa;
+    size_t size = sizeof *sfa + actions_len;
     struct sw_flow *flow = malloc(sizeof *flow);
     if (!flow)
         return NULL;
 
-    sfa = malloc(n_actions * sizeof sfa->actions[0]);
+    sfa = malloc(size);
     if (!sfa) {
         free(flow);
         return NULL;
     }
-    sfa->n_actions = n_actions;
+    sfa->actions_len = actions_len;
     flow->sf_acts = sfa;
     return flow;
 }
@@ -199,18 +202,18 @@ flow_free(struct sw_flow *flow)
 
 /* Copies 'actions' into a newly allocated structure for use by 'flow'
  * and frees the structure that defined the previous actions. */
-void flow_replace_acts(struct sw_flow *flow, const struct ofp_action *actions,
-        int n_actions)
+void flow_replace_acts(struct sw_flow *flow, 
+        const struct ofp_action_header *actions, size_t actions_len)
 {
     struct sw_flow_actions *sfa;
-    int size = sizeof *sfa + (n_actions * sizeof sfa->actions[0]);
+    int size = sizeof *sfa + actions_len;
 
     sfa = malloc(size);
     if (unlikely(!sfa))
         return;
 
-    sfa->n_actions = n_actions;
-    memcpy(sfa->actions, actions, n_actions * sizeof sfa->actions[0]);
+    sfa->actions_len = actions_len;
+    memcpy(sfa->actions, actions, actions_len);
 
     free(flow->sf_acts);
     flow->sf_acts = sfa;
@@ -259,7 +262,35 @@ bool flow_timeout(struct sw_flow *flow)
     }
 }
 
-void flow_used(struct sw_flow *flow, struct buffer *buffer)
+/* Returns nonzero if 'flow' contains an output action to 'out_port' or
+ * has the value OFPP_NONE. 'out_port' is in network-byte order. */
+int flow_has_out_port(struct sw_flow *flow, uint16_t out_port)
+{
+    struct sw_flow_actions *sf_acts = flow->sf_acts;
+    size_t actions_len = sf_acts->actions_len;
+    uint8_t *p = (uint8_t *)sf_acts->actions;
+
+    if (out_port == htons(OFPP_NONE))
+        return 1;
+
+    while (actions_len > 0) {
+        struct ofp_action_header *ah = (struct ofp_action_header *)p;
+        size_t len = ntohs(ah->len);
+
+        if (ah->type == htons(OFPAT_OUTPUT)) {
+            struct ofp_action_output *oa = (struct ofp_action_output *)p;
+            if (oa->port == out_port) {
+                return 1;
+            }
+        }
+        p += len;
+        actions_len -= len;
+    }
+
+    return 0;
+}
+
+void flow_used(struct sw_flow *flow, struct ofpbuf *buffer)
 {
     flow->used = time_now();
     flow->packet_count++;