ofp-msgs: Open Flow 1.1 and 1.2 Port Status Messages
[openvswitch] / lib / match.c
index d337c1b721f48f43695e4832a53bf8b8e855f927..b25569d98f6353eb7389f2143b2a7b4e88c2afa1 100644 (file)
@@ -37,8 +37,12 @@ match_init(struct match *match,
 void
 match_init_exact(struct match *match, const struct flow *flow)
 {
+    ovs_be64 tun_id = flow->tunnel.tun_id;
+
     match->flow = *flow;
     match->flow.skb_priority = 0;
+    memset(&match->flow.tunnel, 0, sizeof match->flow.tunnel);
+    match->flow.tunnel.tun_id = tun_id;
     flow_wildcards_init_exact(&match->wc);
 }
 
@@ -102,8 +106,8 @@ match_set_tun_id(struct match *match, ovs_be64 tun_id)
 void
 match_set_tun_id_masked(struct match *match, ovs_be64 tun_id, ovs_be64 mask)
 {
-    match->wc.masks.tun_id = mask;
-    match->flow.tun_id = tun_id & mask;
+    match->wc.masks.tunnel.tun_id = mask;
+    match->flow.tunnel.tun_id = tun_id & mask;
 }
 
 void
@@ -626,15 +630,16 @@ match_format(const struct match *match, struct ds *s, unsigned int priority)
             break;
         }
     }
-    switch (wc->masks.tun_id) {
+    switch (wc->masks.tunnel.tun_id) {
     case 0:
         break;
     case CONSTANT_HTONLL(UINT64_MAX):
-        ds_put_format(s, "tun_id=%#"PRIx64",", ntohll(f->tun_id));
+        ds_put_format(s, "tun_id=%#"PRIx64",", ntohll(f->tunnel.tun_id));
         break;
     default:
         ds_put_format(s, "tun_id=%#"PRIx64"/%#"PRIx64",",
-                      ntohll(f->tun_id), ntohll(wc->masks.tun_id));
+                      ntohll(f->tunnel.tun_id),
+                      ntohll(wc->masks.tunnel.tun_id));
         break;
     }
     switch (wc->masks.metadata) {
@@ -773,3 +778,77 @@ match_print(const struct match *match)
     puts(s);
     free(s);
 }
+\f
+/* Initializes 'dst' as a copy of 'src'.  The caller must eventually free 'dst'
+ * with minimatch_destroy(). */
+void
+minimatch_init(struct minimatch *dst, const struct match *src)
+{
+    miniflow_init(&dst->flow, &src->flow);
+    minimask_init(&dst->mask, &src->wc);
+}
+
+/* Initializes 'dst' as a copy of 'src'.  The caller must eventually free 'dst'
+ * with minimatch_destroy(). */
+void
+minimatch_clone(struct minimatch *dst, const struct minimatch *src)
+{
+    miniflow_clone(&dst->flow, &src->flow);
+    minimask_clone(&dst->mask, &src->mask);
+}
+
+/* Frees any memory owned by 'match'.  Does not free the storage in which
+ * 'match' itself resides; the caller is responsible for that. */
+void
+minimatch_destroy(struct minimatch *match)
+{
+    miniflow_destroy(&match->flow);
+    minimask_destroy(&match->mask);
+}
+
+/* Initializes 'dst' as a copy of 'src'. */
+void
+minimatch_expand(const struct minimatch *src, struct match *dst)
+{
+    miniflow_expand(&src->flow, &dst->flow);
+    minimask_expand(&src->mask, &dst->wc);
+}
+
+/* Returns true if 'a' and 'b' match the same packets, false otherwise.  */
+bool
+minimatch_equal(const struct minimatch *a, const struct minimatch *b)
+{
+    return (miniflow_equal(&a->flow, &b->flow)
+            && minimask_equal(&a->mask, &b->mask));
+}
+
+/* Returns a hash value for 'match', given 'basis'. */
+uint32_t
+minimatch_hash(const struct minimatch *match, uint32_t basis)
+{
+    return miniflow_hash(&match->flow, minimask_hash(&match->mask, basis));
+}
+
+/* Appends a string representation of 'match' to 's'.  If 'priority' is
+ * different from OFP_DEFAULT_PRIORITY, includes it in 's'. */
+void
+minimatch_format(const struct minimatch *match, struct ds *s,
+                 unsigned int priority)
+{
+    struct match megamatch;
+
+    minimatch_expand(match, &megamatch);
+    match_format(&megamatch, s, priority);
+}
+
+/* Converts 'match' to a string and returns the string.  If 'priority' is
+ * different from OFP_DEFAULT_PRIORITY, includes it in the string.  The caller
+ * must free the string (with free()). */
+char *
+minimatch_to_string(const struct minimatch *match, unsigned int priority)
+{
+    struct match megamatch;
+
+    minimatch_expand(match, &megamatch);
+    return match_to_string(&megamatch, priority);
+}