vlog: add "vlog/list-pattern" command
[cascardo/ovs.git] / lib / match.c
index b5bea5d..ca9492f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 #include "dynamic-string.h"
 #include "ofp-util.h"
 #include "packets.h"
+#include "tun-metadata.h"
 
 /* Converts the flow in 'flow' into a match in 'match', with the given
  * 'wildcards'. */
@@ -31,6 +32,7 @@ match_init(struct match *match,
     match->flow = *flow;
     match->wc = *wc;
     match_zero_wildcarded_fields(match);
+    memset(&match->tun_md, 0, sizeof match->tun_md);
 }
 
 /* Converts a flow into a match.  It sets the wildcard masks based on
@@ -44,6 +46,8 @@ match_wc_init(struct match *match, const struct flow *flow)
     flow_wildcards_init_for_packet(&match->wc, flow);
     WC_MASK_FIELD(&match->wc, regs);
     WC_MASK_FIELD(&match->wc, metadata);
+
+    memset(&match->tun_md, 0, sizeof match->tun_md);
 }
 
 /* Initializes 'match' as a "catch-all" match that matches every packet. */
@@ -52,6 +56,7 @@ match_init_catchall(struct match *match)
 {
     memset(&match->flow, 0, sizeof match->flow);
     flow_wildcards_init_catchall(&match->wc);
+    memset(&match->tun_md, 0, sizeof match->tun_md);
 }
 
 /* For each bit or field wildcarded in 'match', sets the corresponding bit or
@@ -88,6 +93,13 @@ match_set_recirc_id(struct match *match, uint32_t value)
     match->wc.masks.recirc_id = UINT32_MAX;
 }
 
+void
+match_set_conj_id(struct match *match, uint32_t value)
+{
+    match->flow.conj_id = value;
+    match->wc.masks.conj_id = UINT32_MAX;
+}
+
 void
 match_set_reg(struct match *match, unsigned int reg_idx, uint32_t value)
 {
@@ -217,6 +229,32 @@ match_set_tun_flags_masked(struct match *match, uint16_t flags, uint16_t mask)
     match->flow.tunnel.flags = flags & mask;
 }
 
+void
+match_set_tun_gbp_id_masked(struct match *match, ovs_be16 gbp_id, ovs_be16 mask)
+{
+    match->wc.masks.tunnel.gbp_id = mask;
+    match->flow.tunnel.gbp_id = gbp_id & mask;
+}
+
+void
+match_set_tun_gbp_id(struct match *match, ovs_be16 gbp_id)
+{
+    match_set_tun_gbp_id_masked(match, gbp_id, OVS_BE16_MAX);
+}
+
+void
+match_set_tun_gbp_flags_masked(struct match *match, uint8_t flags, uint8_t mask)
+{
+    match->wc.masks.tunnel.gbp_flags = mask;
+    match->flow.tunnel.gbp_flags = flags & mask;
+}
+
+void
+match_set_tun_gbp_flags(struct match *match, uint8_t flags)
+{
+    match_set_tun_gbp_flags_masked(match, flags, UINT8_MAX);
+}
+
 void
 match_set_in_port(struct match *match, ofp_port_t ofp_port)
 {
@@ -845,6 +883,15 @@ format_flow_tunnel(struct ds *s, const struct match *match)
     format_ip_netmask(s, "tun_src", tnl->ip_src, wc->masks.tunnel.ip_src);
     format_ip_netmask(s, "tun_dst", tnl->ip_dst, wc->masks.tunnel.ip_dst);
 
+    if (wc->masks.tunnel.gbp_id) {
+        format_be16_masked(s, "tun_gbp_id", tnl->gbp_id,
+                           wc->masks.tunnel.gbp_id);
+    }
+
+    if (wc->masks.tunnel.gbp_flags) {
+        ds_put_format(s, "tun_gbp_flags=%#"PRIx8",", tnl->gbp_flags);
+    }
+
     if (wc->masks.tunnel.ip_tos) {
         ds_put_format(s, "tun_tos=%"PRIx8",", tnl->ip_tos);
     }
@@ -855,6 +902,7 @@ format_flow_tunnel(struct ds *s, const struct match *match)
         format_flags(s, flow_tun_flag_to_string, tnl->flags, '|');
         ds_put_char(s, ',');
     }
+    tun_metadata_match_format(s, match);
 }
 
 /* Appends a string representation of 'match' to 's'.  If 'priority' is
@@ -870,7 +918,7 @@ match_format(const struct match *match, struct ds *s, int priority)
 
     int i;
 
-    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 29);
+    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 32);
 
     if (priority != OFP_DEFAULT_PRIORITY) {
         ds_put_format(s, "priority=%d,", priority);
@@ -883,11 +931,15 @@ match_format(const struct match *match, struct ds *s, int priority)
                              wc->masks.recirc_id);
     }
 
-    if (f->dp_hash && wc->masks.dp_hash) {
+    if (wc->masks.dp_hash) {
         format_uint32_masked(s, "dp_hash", f->dp_hash,
                              wc->masks.dp_hash);
     }
 
+    if (wc->masks.conj_id) {
+        ds_put_format(s, "conj_id=%"PRIu32",", f->conj_id);
+    }
+
     if (wc->masks.skb_priority) {
         ds_put_format(s, "skb_priority=%#"PRIx32",", f->skb_priority);
     }
@@ -1180,6 +1232,7 @@ minimatch_expand(const struct minimatch *src, struct match *dst)
 {
     miniflow_expand(&src->flow, &dst->flow);
     minimask_expand(&src->mask, &dst->wc);
+    memset(&dst->tun_md, 0, sizeof dst->tun_md);
 }
 
 /* Returns true if 'a' and 'b' match the same packets, false otherwise.  */