[ovs-dev] [bond megaflow v2 3/5] lib/metaflow: add new flow fields for recirculation

Andy Zhou azhou at nicira.com
Tue Mar 11 23:56:19 UTC 2014


Signed-off-by: Andy Zhou <azhou at nicira.com>

---
v1 -> v2:  Minor adjustment.
---
 lib/match.c     |   26 ++++++++++++++++++++++++
 lib/match.h     |    6 ++++++
 lib/meta-flow.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/meta-flow.h |    2 ++
 4 files changed, 94 insertions(+)

diff --git a/lib/match.c b/lib/match.c
index 12e58a2..8789413 100644
--- a/lib/match.c
+++ b/lib/match.c
@@ -165,6 +165,32 @@ match_zero_wildcarded_fields(struct match *match)
 }
 
 void
+match_set_dp_hash(struct match *match, uint32_t value)
+{
+    match_set_dp_hash_masked(match, value, UINT32_MAX);
+}
+
+void
+match_set_dp_hash_masked(struct match *match, uint32_t value, uint32_t mask)
+{
+    match->wc.masks.dp_hash = mask;
+    match->flow.dp_hash = value & mask;
+}
+
+void
+match_set_recirc_id(struct match *match, uint32_t value)
+{
+    match_set_recirc_id_masked(match, value, UINT32_MAX);
+}
+
+void
+match_set_recirc_id_masked(struct match *match, uint32_t value, uint32_t mask)
+{
+    match->wc.masks.recirc_id = mask;
+    match->flow.recirc_id = value & mask;
+}
+
+void
 match_set_reg(struct match *match, unsigned int reg_idx, uint32_t value)
 {
     match_set_reg_masked(match, reg_idx, value, UINT32_MAX);
diff --git a/lib/match.h b/lib/match.h
index 7a8ae68..95c8e67 100644
--- a/lib/match.h
+++ b/lib/match.h
@@ -41,6 +41,12 @@ void match_init_catchall(struct match *);
 
 void match_zero_wildcarded_fields(struct match *);
 
+void match_set_dp_hash(struct match *, uint32_t value);
+void match_set_dp_hash_masked(struct match *, uint32_t value, uint32_t mask);
+
+void match_set_recirc_id(struct match *, uint32_t value);
+void match_set_recirc_id_masked(struct match *, uint32_t value, uint32_t mask);
+
 void match_set_reg(struct match *, unsigned int reg_idx, uint32_t value);
 void match_set_reg_masked(struct match *, unsigned int reg_idx,
                           uint32_t value, uint32_t mask);
diff --git a/lib/meta-flow.c b/lib/meta-flow.c
index d90477a..248d1f0 100644
--- a/lib/meta-flow.c
+++ b/lib/meta-flow.c
@@ -52,6 +52,30 @@ const struct mf_field mf_fields[MFF_N_IDS] = {
     /* ## -------- ## */
 
     {
+        MFF_DP_HASH, "dp_hash", NULL,
+        MF_FIELD_SIZES(be32),
+        MFM_FULLY,
+        MFS_HEXADECIMAL,
+        MFP_NONE,
+        false,
+        NXM_NX_DP_HASH, "NXM_NX_DP_HASH",
+        NXM_NX_DP_HASH, "NXM_NX_DP_HASH",
+        OFPUTIL_P_NXM_OXM_ANY,
+        OFPUTIL_P_NXM_OXM_ANY,
+        -1,
+    }, {
+        MFF_RECIRC_ID, "recirc_id", NULL,
+        MF_FIELD_SIZES(be32),
+        MFM_FULLY,
+        MFS_DECIMAL,
+        MFP_NONE,
+        false,
+        NXM_NX_RECIRC_ID, "NXM_NX_RECIRC_ID",
+        NXM_NX_RECIRC_ID, "NXM_NX_RECIRC_ID",
+        OFPUTIL_P_NXM_OXM_ANY,
+        OFPUTIL_P_NXM_OXM_ANY,
+        -1,
+    }, {
         MFF_TUN_ID, "tun_id", "tunnel_id",
         MF_FIELD_SIZES(be64),
         MFM_FULLY,
@@ -879,6 +903,10 @@ bool
 mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc)
 {
     switch (mf->id) {
+    case MFF_DP_HASH:
+        return !wc->masks.dp_hash;
+    case MFF_RECIRC_ID:
+        return !wc->masks.recirc_id;
     case MFF_TUN_SRC:
         return !wc->masks.tunnel.ip_src;
     case MFF_TUN_DST:
@@ -1124,6 +1152,8 @@ bool
 mf_is_value_valid(const struct mf_field *mf, const union mf_value *value)
 {
     switch (mf->id) {
+    case MFF_DP_HASH:
+    case MFF_RECIRC_ID:
     case MFF_TUN_ID:
     case MFF_TUN_SRC:
     case MFF_TUN_DST:
@@ -1217,6 +1247,12 @@ mf_get_value(const struct mf_field *mf, const struct flow *flow,
              union mf_value *value)
 {
     switch (mf->id) {
+    case MFF_DP_HASH:
+        value->be32 = htonl(flow->dp_hash);
+        break;
+    case MFF_RECIRC_ID:
+        value->be32 = htonl(flow->recirc_id);
+        break;
     case MFF_TUN_ID:
         value->be64 = flow->tunnel.tun_id;
         break;
@@ -1409,6 +1445,12 @@ mf_set_value(const struct mf_field *mf,
              const union mf_value *value, struct match *match)
 {
     switch (mf->id) {
+    case MFF_DP_HASH:
+        match_set_dp_hash(match, ntohl(value->be32));
+        break;
+    case MFF_RECIRC_ID:
+        match_set_recirc_id(match, ntohl(value->be32));
+        break;
     case MFF_TUN_ID:
         match_set_tun_id(match, value->be64);
         break;
@@ -1622,6 +1664,12 @@ mf_set_flow_value(const struct mf_field *mf,
                   const union mf_value *value, struct flow *flow)
 {
     switch (mf->id) {
+    case MFF_DP_HASH:
+        flow->dp_hash = ntohl(value->be32);
+        break;
+    case MFF_RECIRC_ID:
+        flow->recirc_id = ntohl(value->be32);
+        break;
     case MFF_TUN_ID:
         flow->tunnel.tun_id = value->be64;
         break;
@@ -1834,6 +1882,14 @@ void
 mf_set_wild(const struct mf_field *mf, struct match *match)
 {
     switch (mf->id) {
+    case MFF_DP_HASH:
+        match->flow.dp_hash = 0;
+        match->wc.masks.dp_hash = 0;
+        break;
+    case MFF_RECIRC_ID:
+        match->flow.recirc_id = 0;
+        match->wc.masks.recirc_id = 0;
+        break;
     case MFF_TUN_ID:
         match_set_tun_id_masked(match, htonll(0), htonll(0));
         break;
@@ -2046,6 +2102,7 @@ mf_set(const struct mf_field *mf,
     }
 
     switch (mf->id) {
+    case MFF_RECIRC_ID:
     case MFF_IN_PORT:
     case MFF_IN_PORT_OXM:
     case MFF_SKB_PRIORITY:
@@ -2068,6 +2125,9 @@ mf_set(const struct mf_field *mf,
     case MFF_ICMPV6_CODE:
         return OFPUTIL_P_NONE;
 
+    case MFF_DP_HASH:
+        match_set_dp_hash_masked(match, ntohl(value->be32), ntohl(mask->be32));
+        break;
     case MFF_TUN_ID:
         match_set_tun_id_masked(match, value->be64, mask->be64);
         break;
diff --git a/lib/meta-flow.h b/lib/meta-flow.h
index cf92556..91dfecd 100644
--- a/lib/meta-flow.h
+++ b/lib/meta-flow.h
@@ -33,6 +33,8 @@ struct match;
  * to represent its value. */
 enum OVS_PACKED_ENUM mf_field_id {
     /* Metadata. */
+    MFF_DP_HASH,                /* be32 */
+    MFF_RECIRC_ID,              /* be32 */
     MFF_TUN_ID,                 /* be64 */
     MFF_TUN_SRC,                /* be32 */
     MFF_TUN_DST,                /* be32 */
-- 
1.7.9.5




More information about the dev mailing list